+from random import shuffle, random
+
from bottle import get, post, run, request
import uuid
from geo import distance
+from street_predictor import parse_summary
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):
def add_tips(game):
radius = 0.0025
- cooridnate = game.current_coordinates
- objects = describe_objects(cooridnate[0] - radius, cooridnate[1] - radius, cooridnate[0] + radius,
- cooridnate[1] + radius)
+ coordinate = game.current_coordinates
+ near_objects = describe_objects(coordinate[0] - radius, coordinate[1] - radius, coordinate[0] + radius,
+ coordinate[1] + radius)
- for o in objects['amenities']:
+ 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())
+
+ if success:
+ game.tips.append(f'Недалеко есть улица, имя которой дал(а) {summary}')
+
+ shuffle(game.tips)
+
def show_tips(game, count):
not_shown_tips = [tip for tip in game.tips if tip not in game.shown_tips]
game.shown_tips.append(not_shown_tips[i])
-test_game = Game('test', (56.832469, 60.605989))
+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, 2)
+show_tips(test_game, 20)
games = {'test': test_game}
'amenities': amenities}
-objects = describe_objects(min_lat, min_lon, max_lat, max_lon)
-pp.pprint(objects)
\ No newline at end of file
+if __name__ == '__main__':
+ objects = describe_objects(min_lat, min_lon, max_lat, max_lon)
+ pp.pprint(objects)
\ No newline at end of file
--- /dev/null
+import re
+import wikipedia as w
+
+w.set_lang('ru')
+
+
+def parse_summary(query='str'):
+ print('query: ' + query)
+ try:
+ summary = w.summary(query)
+ full_description = re.split(r'\) —', summary)[1]
+ description = re.split(r'\.', full_description)[0]
+ return True, description.strip()
+ except Exception:
+ return False, ''
+
+if __name__ == '__main__':
+ print(parse_summary('Бебеля'))