]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
add tips api
authorsergeykamaev <sergeykamaev27@gmail.com>
Sat, 18 May 2019 17:02:31 +0000 (22:02 +0500)
committersergeykamaev <sergeykamaev27@gmail.com>
Sat, 18 May 2019 17:08:52 +0000 (22:08 +0500)
app.py
osm/osm.py

diff --git a/app.py b/app.py
index 733e0e17b105821dc923fc725adfedc8f26d34df..946bf6b7d081d3a84873e4258f8be71ccd66302e 100644 (file)
--- a/app.py
+++ b/app.py
@@ -2,6 +2,8 @@ from bottle import get, post, run, request
 import uuid
 from geo import distance
 
+from osm.osm import describe_objects
+
 
 class Game:
     def __init__(self, game_id, current_coordinates):
@@ -12,7 +14,7 @@ class Game:
         self.distance = None
 
 
-games = {}
+games = {'test': Game('test', (56.832469, 60.605989))}
 
 
 @get('/api/games')
@@ -44,6 +46,18 @@ def get_game(game_id):
     }
 
 
+@get('/api/games/<game_id>/tips')
+def get_game(game_id):
+    game = games[game_id]
+    cooridnate = game.current_coordinates
+
+    radius = 0.0025
+    objects = describe_objects(cooridnate[0] - radius, cooridnate[1] - radius, cooridnate[0] + radius,
+                               cooridnate[1] + radius)
+
+    return {'items': [','.join([object['name'] for object in objects['objects']])]}
+
+
 @post('/api/games/<game_id>/finish')
 def finish_game(game_id):
     game = games[game_id]
index 9e5cd7edb99a5ce1f5bc0e46fbc76043e399e44f..204de2b796b01848f355caaf08513b186e9024ea 100644 (file)
@@ -26,7 +26,7 @@ def filter_amenities(objects):
     and 'amenity' in o['data']['tag']
     and 'name' in o['data']['tag'], objects))
 
-def describe_objects(min_lon, min_lat, max_lon, max_lat):
+def describe_objects(min_lat, min_lon, max_lat, max_lon):
     objects = get_objects_from_square(min_lon, min_lat, max_lon, max_lat)
     streets = [
       {'name': x['data']['tag']['name']} for x in filter_streets(objects)
@@ -42,5 +42,5 @@ def describe_objects(min_lon, min_lat, max_lon, max_lat):
             'amenities': remove_duplicates(amenities)}
 
 
-objects = describe_objects(min_lon, min_lat, max_lon, max_lat)
+objects = describe_objects(min_lat, min_lon, max_lat, max_lon)
 pp.pprint(objects)
\ No newline at end of file