This commit is contained in:
Edward Betts 2019-10-10 09:47:38 +01:00
parent bd6d13bc36
commit 312cb255c4
2 changed files with 11 additions and 16 deletions

View file

@ -10,6 +10,12 @@ def get_entity_label(entity):
if len(label_values) == 1:
return list(label_values)[0]
def get_en_value(entity, key):
if 'en' in entity[key]:
return entity[key]['en']['value']
def get_en_label(entity):
if 'en' in entity['labels']:
return entity['labels']['en']['value']
return get_en_value(entity, 'labels')
def get_en_description(entity):
return get_en_value(entity, 'descriptions')

View file

@ -1,18 +1,9 @@
from depicts import mediawiki
from depicts import mediawiki, wikibase
from depicts.model import DepictsItem
def create_depicts_item(item_id):
qid = f'Q{item_id}'
entity = mediawiki.get_entity(qid)
if 'en' in entity['labels']:
label = entity['labels']['en']['value']
else:
label = None
if 'en' in entity['descriptions']:
description = entity['descriptions']['en']['value']
else:
description = None
if 'en' in entity['aliases']:
alt_labels = {alt['value'] for alt in entity['aliases']['en']}
@ -20,9 +11,7 @@ def create_depicts_item(item_id):
alt_labels = set()
return DepictsItem(item_id=item_id,
label=label,
description=description,
label=wikibase.get_en_label(entity),
description=wikibase.get_en_description(entity),
alt_labels=alt_labels,
count=0)