From: zharkovstas Date: Sat, 18 May 2019 18:11:04 +0000 (+0500) Subject: Fixes X-Git-Url: https://git.xn--bdkaa.com/?a=commitdiff_plain;h=142f2af3fe504a0d229dd41496353bf7a46eee39;p=where-are-you.py.git Fixes --- diff --git a/app.py b/app.py index 30de07c..1052a81 100644 --- a/app.py +++ b/app.py @@ -9,6 +9,7 @@ from osm.osm import describe_objects min_lat, max_lat, min_lon, max_lon = 56.807556, 56.847826, 60.570744, 60.657791 + class Game: def __init__(self, game_id, current_coordinates): self.id = game_id @@ -24,14 +25,15 @@ def add_tips(game): radius = 0.0025 coordinate = game.current_coordinates near_objects = describe_objects(coordinate[0] - radius, coordinate[1] - radius, coordinate[0] + radius, - coordinate[1] + radius) + coordinate[1] + radius) for o in near_objects['amenities']: game.tips.append(f'Рядом с вами находится {o["name"]}') for s in near_objects['streets']: - success, summary = parse_summary(s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip()) + success, summary = parse_summary( + s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip()) if success: game.tips.append(f'Недалеко есть улица, имя которой дал(а) {summary}') @@ -46,13 +48,18 @@ def show_tips(game, count): game.shown_tips.append(not_shown_tips[i]) -lat = min_lat + (max_lat - min_lat) * random() -lon = min_lon + (max_lon - min_lon) * random() +def create_test_game(): + lat = min_lat + (max_lat - min_lat) * random() + lon = min_lon + (max_lon - min_lon) * random() + + test_game = Game('test', (lat, lon)) + add_tips(test_game) + show_tips(test_game, 20) + + return test_game -test_game = Game('test', (lat, lon)) -add_tips(test_game) -show_tips(test_game, 20) -games = {'test': test_game} + +games = {'test': create_test_game()} @get('/api/games') @@ -67,7 +74,10 @@ def get_games(): def post_game(): game_id = str(uuid.uuid4()) - game = Game(game_id, (56.832469, 60.605989)) + lat = min_lat + (max_lat - min_lat) * random() + lon = min_lon + (max_lon - min_lon) * random() + + game = Game(game_id, (lat, lon)) games[game_id] = game return { diff --git a/street_predictor.py b/street_predictor.py index bfea4b2..6322341 100644 --- a/street_predictor.py +++ b/street_predictor.py @@ -5,7 +5,7 @@ w.set_lang('ru') def parse_summary(query='str'): - print('query: ' + query) + #print('query: ' + query) try: summary = w.summary(query) full_description = re.split(r'\) —', summary)[1]