def add_sites(): PATH = str(Path(__file__).parent) sites = Knead(PATH + "/data/zomergasten/guest-sites.csv").data() for site in sites: qid = site["qid"] url = site["url"] name = site["guest"] print() print(f"Now handling {qid} / {name}") item = WikidataItem(qid) claims = item.get_claims() if Props.OFFICIAL_WEBSITE in claims: print("Already got a site, skip") continue item.add_url_claim( Props.OFFICIAL_WEBSITE, url, qualifiers=[item.get_item_claim(Props.LANGUAGE_WORK, Items.DUTCH)], references=[ item.get_claim(Props.RETRIEVED, wbtime_now()), item.get_url_claim( Props.REF_URL, "https://www.vpro.nl/programmas/zomergasten/a-z.html"), item.get_item_claim(Props.LANGUAGE_WORK, Items.DUTCH) ])
def main(): items = Knead(PATH + "/data/uds/monuments-with-qids.csv").data() skiplist = Skiplist("projects/skiplists/uds.txt") for index, item in enumerate(items): print(item) qid = item["qid"] bag = item["bag_ok"] url = item["url"] print() print(f"#{index} / #{len(items)}") print(f"Handling {qid} / {bag} / {url}") if skiplist.has(qid): print(f"{qid} in skiplist, skipping") continue wd_item = WikidataItem(qid) claims = wd_item.get_claims() if Props.BAG_BUILDING in claims: print("This item already has a BAG building ID, skipping") continue wd_item.add_string_claim( Props.BAG_BUILDING, bag, references=[ wd_item.get_item_claim(Props.STATED_IN, Items.UDS_DOC), wd_item.get_url_claim(Props.REF_URL, url), wd_item.get_item_claim(Props.LANGUAGE_WORK, Items.DUTCH) ]) skiplist.add(qid)
def add_image_alias(item): qid = item["item"] img = item["Afbeelding"] alias = item["alias"] item = WikidataItem(qid) claims = item.get_claims() aliases = item.get_aliases("nl") if img != "" and Props.IMAGE not in claims: item.add_commonsmedia( Props.IMAGE, img, references = [ item.get_item_claim(Props.IMPORTED_FROM, Items.WIKIPEDIA_NL), item.get_url_claim(Props.WM_IMPORT_URL, WP_PERMALINK) ] ) else: print("has an image already") if (alias != "") and (not aliases): print(f"Setting alias: {alias}") item.edit_aliases({ "nl" : [ alias ] }) else: print("Already has aliases")
def add_party_data(row): print("----" * 20) print() print(row) title = row["title"] qid = row["qid"] if skiplist.has(qid): print(f"In skiplist, skipping") return item = WikidataItem(qid) if Props.NR_OF_SEATS in item.get_claims(): print("Got seats already, skipping party") return for key, val in row.items(): if not key.isdigit(): continue year = int(key) if val == "": continue seats = int(val) print(f"{title} ({qid}) had {seats} seats in {year}") item.add_quantity_claim( Props.NR_OF_SEATS, seats, qualifiers=[ item.get_item_claim(Props.LEGISLATIVE_BODY, Items.NL_LOWER_HOUSE), item.get_claim(Props.START_TIME, WbTime(year=year)) ], references=[ item.get_item_claim(Props.IMPORTED_FROM, Items.WIKIPEDIA_NL), item.get_url_claim(Props.WM_IMPORT_URL, WP_PERMALINK) ]) skiplist.add(qid)
def main(): items = Knead("projects/data/churchseats/seats-qids.csv").data() skiplist = Skiplist("projects/skiplists/churchseats.txt") permalink = "https://nl.wikipedia.org/w/index.php?title=Lijst_van_grootste_Nederlandse_kerkgebouwen_naar_zitplaatsen&oldid=56777124" for index, item in enumerate(items): qid = item["qid"] title = item["name"] seats = item["seats"] print() print(f"#{index} / #{len(items)}") print(f"Handling {qid} / {title} / {seats} seats") print(item) if skiplist.has(qid): print(f"{qid} in skiplist, skipping") continue wd_item = WikidataItem(qid) claims = wd_item.get_claims() if Props.CAPACITY in claims: print("This item already has capacity, skipping") continue wd_item.add_quantity_claim( Props.CAPACITY, seats, references=[ wd_item.get_item_claim(Props.IMPORTED_FROM, Items.WIKIPEDIA_NL), wd_item.get_url_claim(Props.WM_IMPORT_URL, permalink) ]) skiplist.add(qid)