From e90da1bceee28bf061c9cc3543f7ce0e7f67bdb9 Mon Sep 17 00:00:00 2001 From: Vladislav Skukov Date: Sun, 19 May 2019 02:48:47 +0500 Subject: [PATCH] cosmetic effects for tips --- app.py | 17 +++++++++-------- string_formats.py | 8 ++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 string_formats.py diff --git a/app.py b/app.py index 2b9c45a..c17b15a 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ from bottle import get, post, run, request, static_file, response import uuid from geo import distance, move_coordinate from street_predictor import parse_summary +from string_formats import choose_numeral_form from osm.osm import describe_objects @@ -51,18 +52,18 @@ def add_tips(game): s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip()) if success: - game.tips.append(f'Недалеко есть улица, имя которой дал(а) {summary}') + game.tips.append(f'Ассоциативный ряд: название улицы рядом, это — {summary}') buildings = near_objects['buildings'] if len(buildings) > 0: game.tips.append( - 'Вы рядом с ' + convert_building_type(buildings[0]['building_type']) + ' высотой в ' + buildings[0][ - 'levels'] + ' этажей') + 'Вы рядом ' + convert_building_type(buildings[0]['building_type']) + ' высотой в ' + buildings[0][ + 'levels'] + choose_numeral_form(buildings[0]['levels'], ' этаж', ' этажа', ' этажей')) for v in itertools.islice(near_objects['vehicles'], 3): if v['vehicle_type'] == 'train': - game.tips.append(f'Мимо пронесся поезд') + game.tips.append(f'Мимо пронесся поезд 🚂') else: game.tips.append(f'Мимо как раз проезжает полупустой {v["name"]}. Можно успеть') @@ -75,13 +76,13 @@ def add_tips(game): def convert_building_type(building_type): if building_type == 'dormitory': - return 'общежитием' + return 'с общежитием' if building_type == 'garage': - return 'гаражом' + return 'с гаражом' if building_type == 'apartments': - return 'жилым домом' + return 'с жилым домом' else: - return 'зданием' + return 'со зданием 🏢' def convert_direction(direction): diff --git a/string_formats.py b/string_formats.py new file mode 100644 index 0000000..df540c8 --- /dev/null +++ b/string_formats.py @@ -0,0 +1,8 @@ +def choose_numeral_form(l, form1, form2, form5): + l = l % 100 + if (l > 10 and l < 20): + return form5 + l = l % 10 + indices = [ 2, 0, 1, 1, 1, 2, 2, 2, 2, 2 ] + one_two_five = [form1, form2, form5] + return one_two_five[indices[l]] \ No newline at end of file -- 2.50.1