[fix] code cleanup

This commit is contained in:
Adam Tauber 2014-10-04 22:53:54 +02:00
parent a48028b771
commit 727c7226d9

View file

@ -1,7 +1,6 @@
import json
from requests import get
from urllib import urlencode
from datetime import datetime
resultCount=2
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):
params['url'] = urlSearch.format(query=urlencode({'srsearch': query, 'srlimit': resultCount}))
print params['url']
return params
@ -27,9 +25,7 @@ def response(resp):
language = 'en'
url = urlDetail.format(query=urlencode({'ids': '|'.join(wikidata_ids), 'languages': language + '|en'}))
before = datetime.now()
htmlresponse = get(url)
print datetime.now() - before
jsonresponse = json.loads(htmlresponse.content)
for wikidata_id in wikidata_ids:
results = results + getDetail(jsonresponse, wikidata_id, language)
@ -144,7 +140,6 @@ def get_string(claims, propertyName, defaultValue=None):
for e in propValue:
mainsnak = e.get('mainsnak', {})
datatype = mainsnak.get('datatype', '')
datavalue = mainsnak.get('datavalue', {})
if datavalue != None:
result.append(datavalue.get('value', ''))
@ -164,7 +159,6 @@ def get_time(claims, propertyName, defaultValue=None):
for e in propValue:
mainsnak = e.get('mainsnak', {})
datatype = mainsnak.get('datatype', '')
datavalue = mainsnak.get('datavalue', {})
if datavalue != None:
value = datavalue.get('value', '')