Create missing depicts items.
This commit is contained in:
parent
1ef188fa06
commit
545311112b
19
app.py
19
app.py
|
@ -293,28 +293,25 @@ def existing_depicts_from_entity(entity):
|
||||||
if 'P180' not in entity['claims']:
|
if 'P180' not in entity['claims']:
|
||||||
return []
|
return []
|
||||||
existing = []
|
existing = []
|
||||||
|
new_depicts = False
|
||||||
for claim in entity['claims']['P180']:
|
for claim in entity['claims']['P180']:
|
||||||
item_id = claim['mainsnak']['datavalue']['value']['numeric-id']
|
item_id = claim['mainsnak']['datavalue']['value']['numeric-id']
|
||||||
|
|
||||||
item = DepictsItem.query.get(item_id)
|
item = DepictsItem.query.get(item_id)
|
||||||
if item:
|
if not item:
|
||||||
|
item = wikidata_edit.create_depicts_item(item_id)
|
||||||
|
database.session.add(item)
|
||||||
|
new_depicts = True
|
||||||
d = {
|
d = {
|
||||||
'label': item.label,
|
'label': item.label,
|
||||||
'description': item.description,
|
'description': item.description,
|
||||||
'qid': item.qid,
|
'qid': f'Q{item.item_id}',
|
||||||
'count': item.count,
|
'count': item.count,
|
||||||
'existing': True,
|
'existing': True,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
qid = f'Q{item_id}'
|
|
||||||
d = {
|
|
||||||
'label': 'not in db',
|
|
||||||
'description': '',
|
|
||||||
'qid': qid,
|
|
||||||
'count': 0,
|
|
||||||
'existing': True,
|
|
||||||
}
|
|
||||||
existing.append(d)
|
existing.append(d)
|
||||||
|
if new_depicts:
|
||||||
|
database.session.commit()
|
||||||
return existing
|
return existing
|
||||||
|
|
||||||
def get_institution(entity, other):
|
def get_institution(entity, other):
|
||||||
|
|
Loading…
Reference in a new issue