Skip to content

Instantly share code, notes, and snippets.

@Ladsgroup
Created September 3, 2017 20:15
Show Gist options
  • Save Ladsgroup/49944ce4c2517f94eabed644ddbb107a to your computer and use it in GitHub Desktop.
Save Ladsgroup/49944ce4c2517f94eabed644ddbb107a to your computer and use it in GitHub Desktop.
Nick fixes
# License: MIT
import pywikibot
import sys
with open('nick_fixes.txt', 'r') as f:
cases = f.read().split('\n')
sites = {'wikidata': pywikibot.Site('wikidata', 'wikidata')}
ok = True
fixes = [
['== Share your experience and feedback as a Wikimedian in this global survey ==', ['<ref>']],
['== شارك خبراتك وآرائك وملاحظاتك معنا بصفتك ويكيميدي في هذا الاستطلاع العالمي ==', ['<ref>']],
['== Teile deine Erfahrungen und gib uns Feedback in dieser globalen Umfrage ==', ['<ref>']],
['== Comparta su experiencia y retroalimente como wikimedista en esta encuesta global ==', ['<ref>']],
['== Partagez votre expérience de wikimédien dans cette enquête générale ==', ['<ref>']],
['== Condividi la tua esperienza e le tue valutazioni come Wikimediano tramite questo sondaggio globale ==', ['<ref>']],
['== ウィキメディアンとしてのご経験とご意見をシェアする世界的調査 ==', ['<ref>']],
['== Podziel się swoim doświadczeniem i przekaż opinię jako Wikimedianin w globalnej ankiecie ==', ['<ref>']],
['== Compartilhe suas experiências e comentários como wikimedista na nossa nova pesquisa ==', ['<ref>']],
['== Поділіться своїм досвідом і відгуком вікімедійця у цьому глобальному опитуванні ==', ['<ref>']],
]
for case in cases:
if case == 'w:ar:User talk:Zahiralbarqi':
ok = True
if not ok:
continue
print(case)
if case.startswith('d:'):
site_code = 'wikidata'
title = 'd:'.join(case.split('d:')[1:])
elif case.startswith('w:'):
site_code = case.split('w:')[1].split(':')[0]
title = ':'.join(case[2:].split(':')[1:])
else:
continue
if site_code not in sites:
sites[site_code] = pywikibot.Site(site_code)
site = sites[site_code]
page = pywikibot.Page(site, title)
try:
text = page.get()
except KeyboardInterrupt:
sys.exit()
except:
continue
do_not_fix = False
new_text = text
for fix in fixes:
if not fix[0] in text:
continue
section = text.split(fix[0])[1].split('\n==')[0]
if '<references group=survey />' in section and '<ref>' not in section:
print('wwww')
do_not_fix = True
continue
for fixx in fix[1]:
new_section = section.replace(fixx, fixx.replace('<ref>', '<ref group=survey>'))
if new_section.count('-->') != 1:
do_not_fix = True
continue
if new_section.split('-->')[1].replace('<references group=survey />', '').replace('\n', '').replace('\t', '').strip() != '':
do_not_fix = True
continue
if '<references group=survey />' not in section:
new_section = new_section.replace('-->', '-->\n<references group=survey />')
new_text = new_text.replace(section, new_section)
if new_text != text and not do_not_fix:
try:
page.put(new_text, 'Automatic message fix')
except KeyboardInterrupt:
sys.exit()
except:
continue
# License: MIT
import pywikibot
import sys
with open('nick_fixes2.txt', 'r') as f:
cases = f.read().split('\n')
sites = {}
ok = True
fixes = [
['== Share your experience and feedback as a Wikimedian in this global survey ==', ['<ref>']],
['== شارك خبراتك وآرائك وملاحظاتك معنا بصفتك ويكيميدي في هذا الاستطلاع العالمي ==', ['<ref>']],
['== Teile deine Erfahrungen und gib uns Feedback in dieser globalen Umfrage ==', ['<ref>']],
['== Comparta su experiencia y retroalimente como wikimedista en esta encuesta global ==', ['<ref>']],
['== Partagez votre expérience de wikimédien dans cette enquête générale ==', ['<ref>']],
['== Condividi la tua esperienza e le tue valutazioni come Wikimediano tramite questo sondaggio globale ==', ['<ref>']],
['== ウィキメディアンとしてのご経験とご意見をシェアする世界的調査 ==', ['<ref>']],
['== Podziel się swoim doświadczeniem i przekaż opinię jako Wikimedianin w globalnej ankiecie ==', ['<ref>']],
['== Compartilhe suas experiências e comentários como wikimedista na nossa nova pesquisa ==', ['<ref>']],
['== Поділіться своїм досвідом і відгуком вікімедійця у цьому глобальному опитуванні ==', ['<ref>']],
]
for case in cases:
if case == 'w:ar:User talk:Zahiralbarqi':
ok = True
if not ok:
continue
print(case)
if case.startswith(':User talk:'):
site_code = case.split('| site = ')[1].split('.wikipedia')[0]
title = case[1:].split(' | site = ')[0]
else:
continue
if site_code not in sites:
sites[site_code] = pywikibot.Site(site_code)
site = sites[site_code]
page = pywikibot.Page(site, title)
try:
text = page.get()
except KeyboardInterrupt:
sys.exit()
except:
continue
do_not_fix = False
new_text = text
for fix in fixes:
if not fix[0] in text:
continue
section = text.split(fix[0])[1].split('\n==')[0]
if '<references group=survey />' in section and '<ref>' not in section:
print('wwww')
do_not_fix = True
continue
for fixx in fix[1]:
new_section = section.replace(fixx, fixx.replace('<ref>', '<ref group=survey>'))
if new_section.count('-->') != 1:
do_not_fix = True
continue
if new_section.split('-->')[1].replace('<references group=survey />', '').replace('\n', '').replace('\t', '').strip() != '':
do_not_fix = True
continue
if '<references group=survey />' not in section:
new_section = new_section.replace('-->', '-->\n<references group=survey />')
new_text = new_text.replace(section, new_section)
if new_text != text and not do_not_fix:
try:
page.put(new_text, 'Automatic message fix')
except KeyboardInterrupt:
sys.exit()
except:
continue
# License: MIT
import pywikibot
import sys
with open('nick_fixes3.txt', 'r') as f:
cases = f.read().split('\n')
sites = {}
ok = True
fixes = [
['== Share your experience and feedback as a Wikimedian in this global survey ==', ['<ref>']],
['== شارك خبراتك وآرائك وملاحظاتك معنا بصفتك ويكيميدي في هذا الاستطلاع العالمي ==', ['<ref>']],
['== Teile deine Erfahrungen und gib uns Feedback in dieser globalen Umfrage ==', ['<ref>']],
['== Comparta su experiencia y retroalimente como wikimedista en esta encuesta global ==', ['<ref>']],
['== Partagez votre expérience de wikimédien dans cette enquête générale ==', ['<ref>']],
['== Condividi la tua esperienza e le tue valutazioni come Wikimediano tramite questo sondaggio globale ==', ['<ref>']],
['== ウィキメディアンとしてのご経験とご意見をシェアする世界的調査 ==', ['<ref>']],
['== Podziel się swoim doświadczeniem i przekaż opinię jako Wikimedianin w globalnej ankiecie ==', ['<ref>']],
['== Compartilhe suas experiências e comentários como wikimedista na nossa nova pesquisa ==', ['<ref>']],
['== Поділіться своїм досвідом і відгуком вікімедійця у цьому глобальному опитуванні ==', ['<ref>']],
]
for case in cases:
if case == 'w:ar:User talk:Zahiralbarqi':
ok = True
if not ok:
continue
print(case)
if case.startswith(':User talk:'):
if '.' not in case.split('| site = ')[1]:
continue
site_code = case.split('| site = ')[1].split('.')[0]
site_family = case.split('| site = ')[1].split('.')[1]
if site_family == 'wikimedia':
site_family = site_code
title = case[1:].split(' | site = ')[0]
else:
continue
if site_code not in sites:
sites[site_code+':'+site_family] = pywikibot.Site(site_code, site_family)
site = sites[site_code+':'+site_family]
page = pywikibot.Page(site, title)
try:
text = page.get()
except KeyboardInterrupt:
sys.exit()
except:
continue
do_not_fix = False
new_text = text
for fix in fixes:
if not fix[0] in text:
continue
section = text.split(fix[0])[1].split('\n==')[0]
if '<references group=survey />' in section and '<ref>' not in section:
do_not_fix = True
continue
for fixx in fix[1]:
new_section = section.replace(fixx, fixx.replace('<ref>', '<ref group=survey>'))
if new_section.count('-->') != 1:
do_not_fix = True
continue
if new_section.split('-->')[1].replace('<references group=survey />', '').replace('\n', '').replace('\t', '').strip() != '':
do_not_fix = True
continue
if '<references group=survey />' not in section:
new_section = new_section.replace('-->', '-->\n<references group=survey />')
new_text = new_text.replace(section, new_section)
if new_text != text and not do_not_fix:
try:
page.put(new_text, 'Automatic message fix')
except KeyboardInterrupt:
sys.exit()
except:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment