-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstatements.py
More file actions
24 lines (21 loc) · 819 Bytes
/
statements.py
File metadata and controls
24 lines (21 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pywikibot
from pywikibot import page
wikidata = pywikibot.Site('wikidata', 'wikidata') # any site will work, this is just an example
repo = wikidata.data_repository() # this is a DataSite object
def write(category, items, claims):
result = []
for q in items:
item = pywikibot.ItemPage(repo, q)
if item.isRedirectPage():
item = item.getRedirectTarget()
item.get()
for prop in claims:
if prop not in item.claims:
if("Value" in claims[prop]):
target = claims[prop]["Value"]
write_statement(item, prop, target)
def write_statement(item, prop, target):
claim = pywikibot.Claim(repo, prop)
target = pywikibot.ItemPage(repo, target)
claim.setTarget(target)
item.addClaim(claim)