Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.