From eaef6d3ebbe73e079165fed3641055e957cd0a91 Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Sun, 19 May 2019 00:30:32 +0500 Subject: [PATCH] Moving fixes + wiki cache --- app.py | 16 ++++++++++++++-- street_predictor.py | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 4df0094..d1b3e2e 100644 --- a/app.py +++ b/app.py @@ -20,7 +20,7 @@ class Game: self.tips = [] self.shown_tips = [] - def move(self, direction, value=100): + def move(self, direction, value=300): if direction == 'north': self.current_coordinates = move_coordinate(self.current_coordinates[0], value), self.current_coordinates[1] elif direction == 'south': @@ -69,6 +69,18 @@ def convert_building_type(building_type): return 'зданием' +def convert_direction(direction): + if direction == 'north': + return 'север' + if direction == 'south': + return 'юг' + if direction == 'east': + return 'восток' + if direction == 'west': + return 'запад' + return '' + + def show_tips(game, count): not_shown_tips = [tip for tip in game.tips if tip not in game.shown_tips] @@ -153,7 +165,7 @@ def get_game(game_id): add_tips(game) - game.shown_tips.append('Вы переместились на 100 м на ' + direction) + game.shown_tips.append('Вы переместились на 100 м на ' + convert_direction(direction)) show_tips(game, 1) diff --git a/street_predictor.py b/street_predictor.py index 6322341..328ba21 100644 --- a/street_predictor.py +++ b/street_predictor.py @@ -3,16 +3,25 @@ import wikipedia as w w.set_lang('ru') +cache = dict() + def parse_summary(query='str'): - #print('query: ' + query) + if query in cache: + return cache[query] + try: summary = w.summary(query) full_description = re.split(r'\) —', summary)[1] description = re.split(r'\.', full_description)[0] + + cache[query] = (True, description.strip()) + return True, description.strip() except Exception: + cache[query] = (False, '') return False, '' + if __name__ == '__main__': print(parse_summary('Бебеля')) -- 2.50.1