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: if len(label_values) == 1:
return list(label_values)[0] 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): def get_en_label(entity):
if 'en' in entity['labels']: return get_en_value(entity, 'labels')
return entity['labels']['en']['value']
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 from depicts.model import DepictsItem
def create_depicts_item(item_id): def create_depicts_item(item_id):
qid = f'Q{item_id}' qid = f'Q{item_id}'
entity = mediawiki.get_entity(qid) 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']: if 'en' in entity['aliases']:
alt_labels = {alt['value'] for alt in entity['aliases']['en']} alt_labels = {alt['value'] for alt in entity['aliases']['en']}
@ -20,9 +11,7 @@ def create_depicts_item(item_id):
alt_labels = set() alt_labels = set()
return DepictsItem(item_id=item_id, return DepictsItem(item_id=item_id,
label=label, label=wikibase.get_en_label(entity),
description=description, description=wikibase.get_en_description(entity),
alt_labels=alt_labels, alt_labels=alt_labels,
count=0) count=0)