]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Moving fixes + wiki cache
authorzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 19:30:32 +0000 (00:30 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sat, 18 May 2019 19:30:32 +0000 (00:30 +0500)
app.py
street_predictor.py

diff --git a/app.py b/app.py
index 4df0094aaa87a1bf54d0b217c8e31fb360887e0e..d1b3e2e9ab7bbd7b2b1425d69b0e07c2da6015e1 100644 (file)
--- 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)
 
index 6322341492e70c6b79134e9c12a4c4c01789ee08..328ba21f637f335b27b62b0f4cf3ee029c80e80d 100644 (file)
@@ -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('Бебеля'))