Skip to content

Instantly share code, notes, and snippets.

@Abbe98
Created October 7, 2017 16:30
Show Gist options
  • Save Abbe98/9dce18f22a45bf4661b296eed046ff77 to your computer and use it in GitHub Desktop.
Save Abbe98/9dce18f22a45bf4661b296eed046ff77 to your computer and use it in GitHub Desktop.
import re
import sys
import pywikibot
import bbr
from pywikibot import pagegenerators
from tqdm import tqdm
pywikibot.handle_args(sys.argv[1:])
site = pywikibot.Site('commons', 'commons')
cat = pywikibot.Category(site,'Category:Kulturarvsdata templates used with incorrect parameters')
gen = pagegenerators.CategorizedPageGenerator(cat)
counter = 0
for page in tqdm(gen):
if 'KMB' in page.title():
if re.search(r'{{BBR\|(\d{14})}}', page.text):
insert_location = re.search(r'{{BBR\|(\d{14})}}', page.text).end() - 2
local_id = re.search(r'{{BBR\|(\d{14})}}', page.text).group(1)
kulturarvsdata = bbr.get_full_uri_from_local_id(local_id)
bbr_type = bbr.get_item_type(kulturarvsdata)
page.text = page.text[:insert_location] + '|'+ bbr_type + page.text[insert_location:]
page.save('added missing parameter to Template:BBR')
counter += 1
if counter == 10:
break
print('done')
print(counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment