forked from zaclys/searxng
[fix] code cleanup
This commit is contained in:
parent
a48028b771
commit
727c7226d9
|
@ -1,7 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from requests import get
|
from requests import get
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
resultCount=2
|
resultCount=2
|
||||||
urlSearch = 'https://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
|
urlSearch = 'https://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
|
||||||
|
@ -10,7 +9,6 @@ urlMap = 'https://www.openstreetmap.org/?lat={latitude}&lon={longitude}&zoom={zo
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
params['url'] = urlSearch.format(query=urlencode({'srsearch': query, 'srlimit': resultCount}))
|
params['url'] = urlSearch.format(query=urlencode({'srsearch': query, 'srlimit': resultCount}))
|
||||||
print params['url']
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,9 +25,7 @@ def response(resp):
|
||||||
language = 'en'
|
language = 'en'
|
||||||
url = urlDetail.format(query=urlencode({'ids': '|'.join(wikidata_ids), 'languages': language + '|en'}))
|
url = urlDetail.format(query=urlencode({'ids': '|'.join(wikidata_ids), 'languages': language + '|en'}))
|
||||||
|
|
||||||
before = datetime.now()
|
|
||||||
htmlresponse = get(url)
|
htmlresponse = get(url)
|
||||||
print datetime.now() - before
|
|
||||||
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)
|
||||||
|
@ -144,7 +140,6 @@ def get_string(claims, propertyName, defaultValue=None):
|
||||||
for e in propValue:
|
for e in propValue:
|
||||||
mainsnak = e.get('mainsnak', {})
|
mainsnak = e.get('mainsnak', {})
|
||||||
|
|
||||||
datatype = mainsnak.get('datatype', '')
|
|
||||||
datavalue = mainsnak.get('datavalue', {})
|
datavalue = mainsnak.get('datavalue', {})
|
||||||
if datavalue != None:
|
if datavalue != None:
|
||||||
result.append(datavalue.get('value', ''))
|
result.append(datavalue.get('value', ''))
|
||||||
|
@ -164,7 +159,6 @@ def get_time(claims, propertyName, defaultValue=None):
|
||||||
for e in propValue:
|
for e in propValue:
|
||||||
mainsnak = e.get('mainsnak', {})
|
mainsnak = e.get('mainsnak', {})
|
||||||
|
|
||||||
datatype = mainsnak.get('datatype', '')
|
|
||||||
datavalue = mainsnak.get('datavalue', {})
|
datavalue = mainsnak.get('datavalue', {})
|
||||||
if datavalue != None:
|
if datavalue != None:
|
||||||
value = datavalue.get('value', '')
|
value = datavalue.get('value', '')
|
||||||
|
|
Loading…
Reference in New Issue