for item_data in data:
img_name = item_data.get('img_name')
if img_name:
page = pywikibot.FilePage(site, img_name)
item = page.data_item()
value_id = pywikibot.ItemPage(repo, 'Q11292718') # Camera's QID from Wikidata
property_id = 'P4082' # 'captured with' property
existing_claims = item.claims.get(property_id, [])
if any(claim.target == value_id for claim in existing_claims):
print(f'"captured with" already exists for {img_name}')
else:
new_claim = pywikibot.Claim(wikidata_site, property_id) # 'captured with' property
new_claim.setTarget(value_id)
item.addClaim(new_claim, bot=True, tags='BotSDC')
print(f'"captured with" added for {img_name}')
else:
print('img_name not found in item_data')