Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2016-06-21 18:48:36 +0300
committerIlya Zverev <zverik@textual.ru>2016-06-28 15:19:13 +0300
commit3fac0435788352bd5cdc67764d9f17b59cbdf501 (patch)
tree81eb4e3dcc0f18be3d33527a3d7338a4e98e835a /tools
parentfb53332984f36004d6ff4e3acbc7cb07d9fec3e9 (diff)
[booking] Save all translations we've got
Diffstat (limited to 'tools')
-rwxr-xr-xtools/python/booking_hotels.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/tools/python/booking_hotels.py b/tools/python/booking_hotels.py
index 7e4a5cc9fc..f684505036 100755
--- a/tools/python/booking_hotels.py
+++ b/tools/python/booking_hotels.py
@@ -17,7 +17,7 @@ import urllib2
logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] %(levelname)s: %(message)s')
# Names starting with '.' are calculated in get_hotel_field() below.
-HOTEL_FIELDS = ('hotel_id', '.lat', '.lon', 'name', 'address', 'class', '.rate', 'ranking', 'review_score', 'url', 'hoteltype_id')
+HOTEL_FIELDS = ('hotel_id', '.lat', '.lon', 'name', 'address', 'class', '.rate', 'ranking', 'review_score', 'url', 'hoteltype_id', '.trans')
class BookingApi:
@@ -160,6 +160,16 @@ def translate(source, output):
return hotel['location']['longitude']
elif field == '.rate':
return rate
+ elif field == '.trans':
+ # Translations are packed into a single column: lang1|name1|address1|lang2|name2|address2|...
+ if 'translations' in hotel:
+ tr_list = []
+ for tr_lang, tr_values in hotel['translations'].items():
+ tr_list.append(tr_lang)
+ tr_list.extend([tr_values[e] for e in ('name', 'address')])
+ return '|'.join([s.replace('|', ';') for s in tr_list])
+ else:
+ return ''
elif field in hotel:
return hotel[field]
raise ValueError('Unknown hotel field: {0}'.format(field))
@@ -175,16 +185,7 @@ def translate(source, output):
while rate <= len(rates) and price > avg * rates[rate - 1]:
rate += 1
l = [get_hotel_field(hotel, e, rate) for e in HOTEL_FIELDS]
- # Add translations for hotel name and address if present.
- if 'translations' in hotel:
- tr_lang = hotel['languagecode']
- if tr_lang not in hotel['translations']:
- tr_lang = hotel['translations'].keys()[0]
- l.append(tr_lang)
- l.extend([hotel['translations'][tr_lang][e] for e in ('name', 'address')])
- else:
- l.extend([''] * 3)
- print('\t'.join([unicode(f).encode('utf8').replace('\t', ' ') for f in l]), file=fd)
+ print('\t'.join([unicode(f).encode('utf8').replace('\t', ' ').replace('\n', ' ').replace('\r', '') for f in l]), file=fd)
def process_options():