on master help sign in
Use human readable date

For DoB and DoD, wikipedia use a non standard ISO format, not easily readable. Now the date is displayed in an human readable form, using the language setting as locale if available. If not, it uses the default locale.

commit7937218be66f1fb3eff02bce308a4e5c78ba6672 authorCqoicebordel <Cqoicebordel@users.noreply.github.com> dateTue 9 Dec 2014, 02:36 (12 years ago) parent41aca9a
1 file changed+15
searx/engines/wikidata.py+15
searx/engines/wikidata.py+15
@@ -1,6 +1,9 @@
11import json
22from requests import get
33from urllib import urlencode
4+import locale
5+import time
6+import dateutil.parser
47
58result_count = 1
69wikidata_host = 'https://www.wikidata.org'
@@ -35,6 +38,16 @@ def response(resp):
3538 language = resp.search_params['language'].split('_')[0]
3639 if language == 'all':
3740 language = 'en'
41+
42+ try:
43+ locale.setlocale(locale.LC_ALL, str(resp.search_params['language']))
44+ except:
45+ try:
46+ locale.setlocale(locale.LC_ALL, 'en_US')
47+ except:
48+ pass
49+ pass
50+
3851 url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids),
3952 'languages': language + '|en'}))
4053
@@ -164,10 +177,12 @@ def getDetail(jsonresponse, wikidata_id, language):
164177
165178 date_of_birth = get_time(claims, 'P569', None)
166179 if date_of_birth is not None:
180+ date_of_birth = dateutil.parser.parse(date_of_birth[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
167181 attributes.append({'label': 'Date of birth', 'value': date_of_birth})
168182
169183 date_of_death = get_time(claims, 'P570', None)
170184 if date_of_death is not None:
185+ date_of_death = dateutil.parser.parse(date_of_death[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
171186 attributes.append({'label': 'Date of death', 'value': date_of_death})
172187
173188 if len(attributes) == 0 and len(urls) == 2 and len(description) == 0: