-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonabot.py
57 lines (48 loc) · 1.97 KB
/
monabot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pywikibot
import inspect
import json
with open("wikidata_ids.json", "r") as file_contents:
artist_ids = json.load(file_contents)
# site = pywikibot.Site("test", "wikidata")
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
limit = 10
counter = 0
for artist_id in artist_ids:
if counter < limit:
item = pywikibot.ItemPage(repo, artist_id)
hasGenre = "P136" in item.claims
if hasGenre:
print(artist_id + " already has claim for P136")
hasPublicArtGenre = pywikibot.ItemPage(repo, "Q557141") in [
claim.target for claim in item.claims["P136"]
]
if hasPublicArtGenre:
print(artist_id + " already has Q557141 as target of P136 claim")
if hasGenre and hasPublicArtGenre:
print("Skipping...\n")
else:
print("Adding P136 claim to " + artist_id)
claim = pywikibot.Claim(
repo, "P136"
) # Adding artistic genre of oeuvre (P136)
target = pywikibot.ItemPage(
repo, "Q557141"
) # Connecting P136 with 'Public art' (Q557141)
claim.setTarget(target)
item.addClaim(
claim,
summary="Bot: Adding claim Public Art as artist's genre to "
+ artist_id
+ ".",
)
url = pywikibot.Claim(repo, "P854") # P854, reference URL
url.setTarget("https://picasso.iro.umontreal.ca/~mona/api/v3/artists")
claim.addSource(
url,
summary="Bot: Adding sources to artistic genre of oeuvre (P136).",
)
counter += 1
print("")
else:
print("Did not modify " + artist_id + "; hit modification limit.")