route_guide_resources.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. import json
  16. import route_guide_pb2
  17. def read_route_guide_database():
  18. """Reads the route guide database.
  19. Returns:
  20. The full contents of the route guide database as a sequence of
  21. route_guide_pb2.Features.
  22. """
  23. feature_list = []
  24. with open("route_guide_db.json") as route_guide_db_file:
  25. for item in json.load(route_guide_db_file):
  26. feature = route_guide_pb2.Feature(
  27. name=item["name"],
  28. location=route_guide_pb2.Point(
  29. latitude=item["location"]["latitude"],
  30. longitude=item["location"]["longitude"]))
  31. feature_list.append(feature)
  32. return feature_list