Skip to content

Instantly share code, notes, and snippets.

@Ladsgroup Ladsgroup/wpc104.py
Last active Jan 22, 2017

Embed
What would you like to do?
# MIT license
import pywikibot
import re
site = pywikibot.Site('en')
page = pywikibot.Page(site, 'Wikipedia:CHECKWIKI/WPC_104_dump')
ok = True
chars = '-\\/'
for case in page.get().split('\n'):
if not case.startswith('*') or '[[' not in case:
continue
article_title = case.split('[[')[1].split(']]')[0]
if article_title == 'Physula':
ok = True
if not ok:
continue
possible_refs = re.findall(r'<nowiki>&lt;ref name\=(.+?) *?/?>', case)
refs = []
for ref in possible_refs:
if ' ' not in ref and '"' not in ref:
if re.search(r'[%s]' % chars, ref):
refs.append(ref)
if not refs:
continue
refs = list(set(refs))
try:
article = pywikibot.Page(site, article_title)
text = article.get()
except:
continue
new_text = text
for ref in refs:
new_text = re.sub(r'(<ref *?name\= *?)(%s)( *?/? *?>)' % re.escape(ref), r'\1"\2"\3', new_text)
if new_text != text:
article.put(new_text, 'Bot: Changes to ref name per [[WP:REFNAME]]')
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.