From 31c018e78975e098519c61153ef5a8dfcb6e802d Mon Sep 17 00:00:00 2001 From: sergeykamaev Date: Sat, 18 May 2019 22:02:31 +0500 Subject: [PATCH] add tips api --- app.py | 16 +++++++++++++++- osm/osm.py | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 733e0e1..946bf6b 100644 --- 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//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//finish') def finish_game(game_id): game = games[game_id] diff --git a/osm/osm.py b/osm/osm.py index 9e5cd7e..204de2b 100644 --- a/osm/osm.py +++ b/osm/osm.py @@ -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 -- 2.50.1