diff options
author | Adam Tauber <asciimoo@gmail.com> | 2015-01-01 14:36:28 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2015-01-01 14:36:28 +0100 |
commit | e3957d6adf5298dbc009a0892f5c088c397c586b (patch) | |
tree | da8d05ed6ea181b9e6be1e69f98aa24a3b159442 /searx | |
parent | 2181c4384ed4d41c795799a345974269327bf641 (diff) | |
parent | 7937218be66f1fb3eff02bce308a4e5c78ba6672 (diff) | |
download | searxng-e3957d6adf5298dbc009a0892f5c088c397c586b.tar.gz searxng-e3957d6adf5298dbc009a0892f5c088c397c586b.zip |
Merge pull request #143 from Cqoicebordel/Wiki-date
Use human readable date for infobox
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/wikidata.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index ab799e6ce..bda80cdca 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -1,6 +1,9 @@ import json from requests import get from urllib import urlencode +import locale +import time +import dateutil.parser result_count = 1 wikidata_host = 'https://www.wikidata.org' @@ -35,6 +38,16 @@ def response(resp): language = resp.search_params['language'].split('_')[0] if language == 'all': language = 'en' + + try: + locale.setlocale(locale.LC_ALL, str(resp.search_params['language'])) + except: + try: + locale.setlocale(locale.LC_ALL, 'en_US') + except: + pass + pass + url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids), 'languages': language + '|en'})) @@ -164,10 +177,12 @@ def getDetail(jsonresponse, wikidata_id, language): date_of_birth = get_time(claims, 'P569', None) if date_of_birth is not None: + date_of_birth = dateutil.parser.parse(date_of_birth[8:]).strftime(locale.nl_langinfo(locale.D_FMT)) attributes.append({'label': 'Date of birth', 'value': date_of_birth}) date_of_death = get_time(claims, 'P570', None) if date_of_death is not None: + date_of_death = dateutil.parser.parse(date_of_death[8:]).strftime(locale.nl_langinfo(locale.D_FMT)) attributes.append({'label': 'Date of death', 'value': date_of_death}) if len(attributes) == 0 and len(urls) == 2 and len(description) == 0: |