Closed traopia closed 3 months ago
ok apparently just changing the function like this worked :) sorry for bothering!
def update_entity(entity_id, property_id, value_id):
try:
statements = []
for v in value_id:
statement = Item(value=v, prop_nr=property_id)
statements.append(statement)
# Fetch the current entity data
entity = wbi.item.get(entity_id)
# Add the new statement to the entity
#entity.claims.add(statement)
entity.claims.add(statements)
# Write the updated entity back to the Wikibase
entity.write()
print(entity_id)
except Exception as e:
# Log the error
#print(e)
pass
I would like to update a set of entities with a statement that needs to have multiple values: Ex: entityA - has children - entityB, entityC, entityD.
I am trying to do it like this:
Where list_values contains all the entities object to be added to the given statement (entityB, entityC, entityD), entity Id is the subject - thus the entity to be updated (entityA) and property ID the property of the statement. Following this code I end up with entityA - has child - entityD, because the object in the statement is overwritten instead of being added. Any lead on how I could fix this? Thanks!