Last active
January 22, 2017 03:12
-
-
Save Ladsgroup/8fd38b14f37702dd8200763f759f64e9 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
# 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><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