Skip to content

Instantly share code, notes, and snippets.

@Ladsgroup
Last active January 22, 2017 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ladsgroup/8fd38b14f37702dd8200763f759f64e9 to your computer and use it in GitHub Desktop.
Save Ladsgroup/8fd38b14f37702dd8200763f759f64e9 to your computer and use it in GitHub Desktop.
# 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