Last active
May 3, 2021 13:59
-
-
Save urbanecm/f0b2bb95514f322207d04908cc4d8143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import pywikibot | |
import json | |
CLAIMS = ['Q41197-3527CCB4-A422-4B31-AED4-BB2CCBF07790'] | |
NEW_RANK = 'deprecated' | |
SUMMARY = 'Deprecating %s' # %s will be replaced with claim ID | |
site = pywikibot.Site('wikidata', 'wikidata') | |
repo = site.data_repository() | |
for claimId in CLAIMS: | |
itemId = claimId.split('-')[0] | |
splitClaimId = '-'.join(claimId.split('-')[1:]) | |
item = pywikibot.ItemPage(repo, itemId) | |
itemData = item.get() | |
for prop in itemData['claims']: | |
for claimData in itemData['claims'][prop]: | |
if claimData.toJSON().get('id') == '%s$%s' % (itemId, splitClaimId): | |
print(claimData.toJSON().get('id')) | |
claimData.setRank(NEW_RANK) | |
item.editEntity({ | |
'claims': [ claimData.toJSON() ] | |
}, summary=SUMMARY % claimId) | |
break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import toolforge | |
import pywikibot | |
site = pywikibot.Site() | |
conn = toolforge.connect('cswiki', cluster='analytics') | |
with conn.cursor() as cur: | |
cur.execute('select page_title from categorylinks join page on page_id=cl_from where page_namespace=0 and cl_to="Obce_v_Bavorsku" and cl_type="page"') | |
data = cur.fetchall() | |
for row in data: | |
page = pywikibot.Page(site, row[0].decode('utf-8')) | |
item = pywikibot.ItemPage.fromPage(page) | |
itemData = item.get() | |
inhab_claims = itemData['claims'].get('P1082', []) | |
for claim in inhab_claims: | |
if claim.rank != "preferred": | |
continue | |
claim.setRank('normal') | |
item.editEntity({ | |
"claims": [ claim.toJSON() ] | |
}, summary='Change P1082 rank to normal') | |
break # no more preferred ranks expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this gist! Spared me hours of digging into documentation :)