|
|
@ -1,8 +1,7 @@
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
from requests import get
|
|
|
|
from requests import get
|
|
|
|
from urllib import urlencode
|
|
|
|
from urllib import urlencode
|
|
|
|
import locale
|
|
|
|
from searx.utils import format_date_by_locale
|
|
|
|
import dateutil.parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result_count = 1
|
|
|
|
result_count = 1
|
|
|
|
wikidata_host = 'https://www.wikidata.org'
|
|
|
|
wikidata_host = 'https://www.wikidata.org'
|
|
|
@ -38,27 +37,18 @@ def response(resp):
|
|
|
|
if language == 'all':
|
|
|
|
if language == 'all':
|
|
|
|
language = 'en'
|
|
|
|
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),
|
|
|
|
url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids),
|
|
|
|
'languages': language + '|en'}))
|
|
|
|
'languages': language + '|en'}))
|
|
|
|
|
|
|
|
|
|
|
|
htmlresponse = get(url)
|
|
|
|
htmlresponse = get(url)
|
|
|
|
jsonresponse = json.loads(htmlresponse.content)
|
|
|
|
jsonresponse = json.loads(htmlresponse.content)
|
|
|
|
for wikidata_id in wikidata_ids:
|
|
|
|
for wikidata_id in wikidata_ids:
|
|
|
|
results = results + getDetail(jsonresponse, wikidata_id, language)
|
|
|
|
results = results + getDetail(jsonresponse, wikidata_id, language, resp.search_params['language'])
|
|
|
|
|
|
|
|
|
|
|
|
return results
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getDetail(jsonresponse, wikidata_id, language):
|
|
|
|
def getDetail(jsonresponse, wikidata_id, language, locale):
|
|
|
|
results = []
|
|
|
|
results = []
|
|
|
|
urls = []
|
|
|
|
urls = []
|
|
|
|
attributes = []
|
|
|
|
attributes = []
|
|
|
@ -176,12 +166,12 @@ def getDetail(jsonresponse, wikidata_id, language):
|
|
|
|
|
|
|
|
|
|
|
|
date_of_birth = get_time(claims, 'P569', None)
|
|
|
|
date_of_birth = get_time(claims, 'P569', None)
|
|
|
|
if date_of_birth is not 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))
|
|
|
|
date_of_birth = format_date_by_locale(date_of_birth[8:], locale)
|
|
|
|
attributes.append({'label': 'Date of birth', 'value': date_of_birth})
|
|
|
|
attributes.append({'label': 'Date of birth', 'value': date_of_birth})
|
|
|
|
|
|
|
|
|
|
|
|
date_of_death = get_time(claims, 'P570', None)
|
|
|
|
date_of_death = get_time(claims, 'P570', None)
|
|
|
|
if date_of_death is not 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))
|
|
|
|
date_of_death = format_date_by_locale(date_of_death[8:], locale)
|
|
|
|
attributes.append({'label': 'Date of death', 'value': date_of_death})
|
|
|
|
attributes.append({'label': 'Date of death', 'value': date_of_death})
|
|
|
|
|
|
|
|
|
|
|
|
if len(attributes) == 0 and len(urls) == 2 and len(description) == 0:
|
|
|
|
if len(attributes) == 0 and len(urls) == 2 and len(description) == 0:
|
|
|
|