summaryrefslogtreecommitdiff
path: root/utils/fetch_currencies.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/fetch_currencies.py')
-rw-r--r--utils/fetch_currencies.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/utils/fetch_currencies.py b/utils/fetch_currencies.py
index 201b32195..3ca8fcfd7 100644
--- a/utils/fetch_currencies.py
+++ b/utils/fetch_currencies.py
@@ -10,17 +10,17 @@ languages = {'de', 'en', 'es', 'fr', 'hu', 'it', 'nl', 'jp'}
url_template = 'https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&{query}&props=labels%7Cdatatype%7Cclaims%7Caliases&languages=' + '|'.join(languages)
url_wmflabs_template = 'http://wdq.wmflabs.org/api?q='
-url_wikidata_search_template='http://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
+url_wikidata_search_template = 'http://www.wikidata.org/w/api.php?action=query&list=search&format=json&srnamespace=0&srprop=sectiontitle&{query}'
wmflabs_queries = [
- 'CLAIM[31:8142]', # all devise
+ 'CLAIM[31:8142]', # all devise
]
db = {
- 'iso4217' : {
- },
- 'names' : {
- }
+ 'iso4217': {
+ },
+ 'names': {
+ }
}
@@ -29,7 +29,7 @@ def remove_accents(data):
def normalize_name(name):
- return re.sub(' +',' ', remove_accents(name.lower()).replace('-', ' '))
+ return re.sub(' +', ' ', remove_accents(name.lower()).replace('-', ' '))
def add_currency_name(name, iso4217):
@@ -37,7 +37,6 @@ def add_currency_name(name, iso4217):
db_names = db['names']
-
if not isinstance(iso4217, basestring):
print "problem", name, iso4217
return
@@ -52,7 +51,7 @@ def add_currency_name(name, iso4217):
if iso4217_set is not None and iso4217 not in iso4217_set:
db_names[name].append(iso4217)
else:
- db_names[name] = [ iso4217 ]
+ db_names[name] = [iso4217]
def add_currency_label(label, iso4217, language):
@@ -85,7 +84,7 @@ def parse_currency(data):
labels = data.get('labels', {})
for language in languages:
name = labels.get(language, {}).get('value', None)
- if name != None:
+ if name is not None:
add_currency_name(name, iso4217)
add_currency_label(name, iso4217, language)
@@ -97,7 +96,7 @@ def parse_currency(data):
def fetch_data(wikidata_ids):
- url = url_template.format(query=urlencode({'ids' : '|'.join(wikidata_ids)}))
+ url = url_template.format(query=urlencode({'ids': '|'.join(wikidata_ids)}))
htmlresponse = get(url)
jsonresponse = json.loads(htmlresponse.content)
entities = jsonresponse.get('entities', {})
@@ -127,7 +126,7 @@ def wdq_query(query):
jsonresponse = json.loads(htmlresponse.content)
qlist = map(add_q, jsonresponse.get('items', {}))
error = jsonresponse.get('status', {}).get('error', None)
- if error != None and error != 'OK':
+ if error is not None and error != 'OK':
print "error for query '" + query + "' :" + error
fetch_data_batch(qlist)