]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Use english wiki for London
authorzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 05:29:23 +0000 (10:29 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 05:29:23 +0000 (10:29 +0500)
app.py
street_predictor.py

diff --git a/app.py b/app.py
index 7f38e92264a99a6f385a9ec53a355da8c6441731..00b55e7ef9eb3d5f5f1d9405bb90b02ef9432b61 100644 (file)
--- a/app.py
+++ b/app.py
@@ -16,21 +16,21 @@ import bottle
 import re
 
 cities = {
-    "Екатеринбург": (56.807556, 56.847826, 60.570744, 60.657791),
-    "Новосибирск": (55.014014, 55.074232, 82.876859, 82.979521),
-    "Пермь": (57.965700, 58.030282, 56.158590, 56.306500),
-    "Ижевск": (56.838417, 56.874474, 53.189986, 53.243514),
-    "Казань": (55.770257, 55.830138, 49.088112, 49.181250),
-    "Самара": (53.171396, 53.299662, 50.066118, 50.288368),
-    "Санкт-Петербург": (59.896114, 59.993548, 30.231423, 30.413881),
-    "Лондон": (51.464854, 51.575864, -0.181617, 0.012276)
+    "Екатеринбург": (56.807556, 56.847826, 60.570744, 60.657791, 'ru'),
+    "Новосибирск": (55.014014, 55.074232, 82.876859, 82.979521, 'ru'),
+    "Пермь": (57.965700, 58.030282, 56.158590, 56.306500, 'ru'),
+    "Ижевск": (56.838417, 56.874474, 53.189986, 53.243514, 'ru'),
+    "Казань": (55.770257, 55.830138, 49.088112, 49.181250, 'ru'),
+    "Самара": (53.171396, 53.299662, 50.066118, 50.288368, 'ru'),
+    "Санкт-Петербург": (59.896114, 59.993548, 30.231423, 30.413881, 'ru'),
+    "Лондон": (51.464854, 51.575864, -0.181617, 0.012276, 'en')
 }
 
 move_distance = 300
 
 
 class Game:
-    def __init__(self, game_id, current_coordinates):
+    def __init__(self, game_id, current_coordinates, lang):
         self.id = game_id
         self.current_coordinates = current_coordinates
         self.is_finished = False
@@ -40,6 +40,7 @@ class Game:
         self.shown_tips = []
         self.route = [current_coordinates]
         self.score = 0
+        self.lang = lang
 
     def move(self, direction, value=move_distance):
         if direction == 'north':
@@ -75,7 +76,7 @@ def add_tips(game):
 
     for s in near_objects['streets']:
         success, summary = parse_summary(
-            s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip())
+            s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip(), game.lang)
 
         if success and summary and 'улица' not in summary and not re.search(stemming(s['name']), stemming(summary),
                                                                             re.IGNORECASE):
@@ -181,12 +182,12 @@ def show_tips(game, count):
 
 
 def create_test_game():
-    min_lat, max_lat, min_lon, max_lon = cities['Екатеринбург']
+    min_lat, max_lat, min_lon, max_lon, lang = cities['Екатеринбург']
 
     lat = min_lat + (max_lat - min_lat) * random()
     lon = min_lon + (max_lon - min_lon) * random()
 
-    test_game = Game('test', (lat, lon))
+    test_game = Game('test', (lat, lon), lang)
     # add_tips(test_game)
     # show_tips(test_game, 2)
 
@@ -232,12 +233,12 @@ def handle_post_game(city_id):
     if city_id not in cities:
         return bottle.HTTPResponse(status=404, body='city not found')
 
-    min_lat, max_lat, min_lon, max_lon = cities[city_id]
+    min_lat, max_lat, min_lon, max_lon, lang = cities[city_id]
 
     lat = min_lat + (max_lat - min_lat) * random()
     lon = min_lon + (max_lon - min_lon) * random()
 
-    game = Game(game_id, (lat, lon))
+    game = Game(game_id, (lat, lon), lang)
     games[game_id] = game
 
     add_tips(game)
index ad5d22edec63220b4120a237f0a3b21c873d6d20..5e6d1e9de5f1ef7516a0464adcd964065e4d5265 100644 (file)
@@ -2,8 +2,6 @@ import re
 import wikipedia as w
 import json
 
-w.set_lang('ru')
-
 cache = dict()
 
 with open('streets-with-descriptions.txt', 'r', encoding='utf-8') as f:
@@ -16,11 +14,12 @@ with open('streets-with-descriptions.txt', 'r', encoding='utf-8') as f:
             cache[kv[0].strip()] = False, ''
 
 
-def parse_summary(query='str'):
+def parse_summary(query='str', lang='ru'):
     if query in cache:
         return cache[query]
 
     try:
+        w.set_lang(lang)
         summary = w.summary(query)
 
         full_description = re.split(r'\) —', summary)[-1]