Last active
August 30, 2015 16:24
-
-
Save Ladsgroup/302d8d387c64df55753a to your computer and use it in GitHub Desktop.
This file contains 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 mwparserfromhell | |
site = pywikibot.Site('meta', fam='meta') | |
page = pywikibot.Page(site, 'Research:Revision scoring as a service/Word lists') | |
text = page.get() | |
wikicode = mwparserfromhell.parse(text) | |
templates = wikicode.filter_templates() | |
for template in templates: | |
if str(template.name).strip() == 'Research:Revision scoring as a service/template/word list item': | |
old_template = str(template) | |
the_dict = {} | |
lang = str(template.get('lang').value).strip() | |
page_lang = pywikibot.Page( | |
site, 'Research:Revision scoring as a service/Word lists/%s' % lang) | |
try: | |
lang_text = page_lang.get() | |
except: | |
continue | |
lang_wikicode = mwparserfromhell.parse(lang_text) | |
the_template = None | |
for lang_tem in lang_wikicode.filter_templates(): | |
if str(lang_tem.name).strip() == 'Research:Revision scoring as a service/template/word list data': | |
the_template = lang_tem | |
break | |
else: | |
continue | |
the_template_text = str(the_template) | |
for param in the_template.params: | |
labels = str(template.get('labels').value).strip() | |
if labels: | |
the_template.add('labels', labels) | |
needs = str(template.get('needs').value).strip() | |
if needs: | |
the_template.add('needs', needs) | |
if str(param.name).strip().startswith('list-'): | |
the_dict[str(param.name).strip().replace('list-', '')] = str(param.value).count('\n#') | |
elif str(param.name).strip() != 'contact': | |
template.add(str(param.name).strip(), str(param.value).strip()) | |
for case in the_dict: | |
if case == 'generated' and the_dict[case]: | |
template.add('gen', str(the_dict[case])) | |
elif case == 'stop' and the_dict[case]: | |
template.add('stopwords', str(the_dict[case])) | |
elif the_dict[case]: | |
template.add(case, str(the_dict[case])) | |
page_lang.put(lang_text.replace(the_template_text, str(the_template)), 'Bot: Update') | |
text = text.replace(old_template, str(template)) | |
page.put(text, 'Update the report based on subpages') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment