1# Copyright 2015 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Common resources used in the gRPC route guide example.""" 15 16import json 17 18import route_guide_pb2 19 20 21def read_route_guide_database(): 22 """Reads the route guide database. 23 24 Returns: 25 The full contents of the route guide database as a sequence of 26 route_guide_pb2.Features. 27 """ 28 feature_list = [] 29 with open("route_guide_db.json") as route_guide_db_file: 30 for item in json.load(route_guide_db_file): 31 feature = route_guide_pb2.Feature( 32 name=item["name"], 33 location=route_guide_pb2.Point( 34 latitude=item["location"]["latitude"], 35 longitude=item["location"]["longitude"])) 36 feature_list.append(feature) 37 return feature_list 38