@@ -1,8 +1,7 @@
2from requests import get
2from requests import get
3from urllib import urlencode
3from urllib import urlencode
4−import locale
4+from searx.utils import format_date_by_locale
7result_count = 1
6result_count = 1
8wikidata_host = 'https://www.wikidata.org'
7wikidata_host = 'https://www.wikidata.org'
@@ -38,27 +37,18 @@ def response(resp):
38 if language == 'all':
37 if language == 'all':
39 language = 'en'
38 language = 'en'
42− locale.setlocale(locale.LC_ALL, str(resp.search_params['language']))
45− locale.setlocale(locale.LC_ALL, 'en_US')
50 url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids),
40 url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids),
51 'languages': language + '|en'}))
41 'languages': language + '|en'}))
53 htmlresponse = get(url)
43 htmlresponse = get(url)
54 jsonresponse = json.loads(htmlresponse.content)
44 jsonresponse = json.loads(htmlresponse.content)
55 for wikidata_id in wikidata_ids:
45 for wikidata_id in wikidata_ids:
56− results = results + getDetail(jsonresponse, wikidata_id, language)
46+ results = results + getDetail(jsonresponse, wikidata_id, language, resp.search_params['language'])
58 return results
48 return results
61−def getDetail(jsonresponse, wikidata_id, language):
51+def getDetail(jsonresponse, wikidata_id, language, locale):
62 results = []
52 results = []
64 attributes = []
54 attributes = []
@@ -176,12 +166,12 @@ def getDetail(jsonresponse, wikidata_id, language):
177 date_of_birth = get_time(claims, 'P569', None)
167 date_of_birth = get_time(claims, 'P569', None)
178 if date_of_birth is not None:
168 if date_of_birth is not None:
179− date_of_birth = dateutil.parser.parse(date_of_birth[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
169+ date_of_birth = format_date_by_locale(date_of_birth[8:], locale)
180 attributes.append({'label': 'Date of birth', 'value': date_of_birth})
170 attributes.append({'label': 'Date of birth', 'value': date_of_birth})
182 date_of_death = get_time(claims, 'P570', None)
172 date_of_death = get_time(claims, 'P570', None)
183 if date_of_death is not None:
173 if date_of_death is not None:
184− date_of_death = dateutil.parser.parse(date_of_death[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
174+ date_of_death = format_date_by_locale(date_of_death[8:], locale)
185 attributes.append({'label': 'Date of death', 'value': date_of_death})
175 attributes.append({'label': 'Date of death', 'value': date_of_death})
187 if len(attributes) == 0 and len(urls) == 2 and len(description) == 0:
177 if len(attributes) == 0 and len(urls) == 2 and len(description) == 0:
@@ -235,7 +225,7 @@ def get_string(claims, propertyName, defaultValue=None):
235 if len(result) == 0:
225 if len(result) == 0:
236 return defaultValue
226 return defaultValue
238− #TODO handle multiple urls
228+ # TODO handle multiple urls
239 return result[0]
229 return result[0]