From 84047fbbd6abbcd049f603853a5ed52cbb86c54c Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Sun, 19 May 2019 01:35:46 +0500 Subject: [PATCH] Improve memorial tips, fix wiki parsing --- app.py | 22 +++++++++++++++++++++- osm/osm.py | 2 +- street_predictor.py | 5 +++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 25c209a..d5e61b5 100644 --- a/app.py +++ b/app.py @@ -64,7 +64,8 @@ def add_tips(game): game.tips.append(f'Мимо как раз проезжает полупустой {v["name"]}. Можно успеть') for s in near_objects['sightseeings']: - game.tips.append(f'Кстати, недалеко интересный туристический объект: ' + s["name"]) + type = convert_sightseeing_type(s['type']) + game.tips.append(f'Кстати, недалеко ' + (type if type else 'интересный туристический объект') + ': ' + s["name"]) shuffle(game.tips) @@ -92,6 +93,25 @@ def convert_direction(direction): return '' +def convert_sightseeing_type(type): + if type == 'memorial': + return 'памятник' + if type == 'attraction': + return None + if type == 'artwork': + return None + if type == 'resort': + return None + if type == 'viewpoint': + return None + if type == 'museum': + return None + if type == 'yes': + return None + if type == 'building': + return None + return None + def show_tips(game, count): not_shown_tips = [tip for tip in game.tips if tip not in game.shown_tips] diff --git a/osm/osm.py b/osm/osm.py index 3ca52ed..3a7d440 100644 --- a/osm/osm.py +++ b/osm/osm.py @@ -109,7 +109,7 @@ def describe_objects(min_lat, min_lon, max_lat, max_lon): 'name': re.split(r'\.', x['data']['tag']['name'].replace(':', '.'))[0]} for x in filter_vehicles(objects) ] sightseeings = [ - {'name': x['data']['tag']['name']} for x in filter_sightseeings(objects) + {'name': x['data']['tag']['name'], 'type': x['data']['tag']['tourism'] if 'tourism' in x['data']['tag'] else x['data']['tag']['historic']} for x in filter_sightseeings(objects) ] districts = [ {'name': x['data']['tag']['name']} for x in filter_districts(objects) diff --git a/street_predictor.py b/street_predictor.py index 328ba21..844146c 100644 --- a/street_predictor.py +++ b/street_predictor.py @@ -12,7 +12,8 @@ def parse_summary(query='str'): try: summary = w.summary(query) - full_description = re.split(r'\) —', summary)[1] + + full_description = re.split(r'\) —', summary)[-1] description = re.split(r'\.', full_description)[0] cache[query] = (True, description.strip()) @@ -24,4 +25,4 @@ def parse_summary(query='str'): if __name__ == '__main__': - print(parse_summary('Бебеля')) + print(parse_summary('Серова')) -- 2.50.1