depicts/depicts/wikidata_edit.py

25 lines
628 B
Python

"""Make an edit to Wikidata."""
from depicts import mediawiki, wikibase
from depicts.model import DepictsItem
def create_depicts_item(item_id: int) -> DepictsItem:
"""Create depicts item."""
qid = f"Q{item_id}"
entity = mediawiki.get_entity(qid)
assert entity
if "en" in entity["aliases"]:
alt_labels = {alt["value"] for alt in entity["aliases"]["en"]}
else:
alt_labels = set()
return DepictsItem(
item_id=item_id,
label=wikibase.get_en_label(entity),
description=wikibase.get_en_description(entity),
alt_labels=alt_labels,
count=0,
)