User:GeoGalvanic/Testspace/River's Template Editing Python Script

River7:35 PM np basically anything where like you want to apply logic to a set of template params is easy af in python from log_into_wiki import * import mwparserfromhell

site = login('me','lol') # Set wiki summary = 'Bot Edit' # Set summary

limit = -1 this_template = site.pages['Template:News Navbox'] # Set template pages = this_template.embeddedin # get the list of pages that transclude the template in question
 * 1) startat_page = 'asdf'
 * 1) there are a lot of other ways to generate a list of pages, but this is probably the most standard that i use

pages_var = list(pages) # in python you can only loop through

pages_array = [p.name for p in pages_var]

try: startat = pages_array.index(startat_page) except NameError as e:   startat = -1 print(startat)

lmt = 0 for page in pages_var: if lmt == limit: break lmt += 1 if lmt < startat: print("Skipping page %s" % page.name) else: text = page.text wikitext = mwparserfromhell.parse(text) for template in wikitext.filter_templates: if template.name.matches('TEMPLATEYOUCAREABOUT'): # TODO newtext = str(wikitext) if text != newtext: print('Saving page %s...' % page.name) page.save(newtext, summary=summary) else: print('Skipping page %s...' % page.name) you just to the TODO there import mwclient

def login(user, wiki): with open('password.txt') as f:       password = f.read with open('password2.txt') as f:       password2 = f.read if user == 'me': site = mwclient.Site('%s.gamepedia.com' % wiki, path='/') site.login('RheingoldRiver@Python', password) return site elif user == 'bot': site = mwclient.Site('%s.gamepedia.com' % wiki, path='/') site.login('RiverIsABot@Python', password2) return site

def report_errors(report_page, page, errors): text = report_page.text error_text = '\n* '.join([e.args[0] for e in errors]) newtext = text + '\n==Python Error Report==\nPage: {} Messages:\n* {}'.format(page, error_text) report_page.save(newtext) and this is log_into_wiki.py               i = 1 tbl = [] changed = False while template.has(fieldname + str(i)): changed = True if template.get(fieldname + str(i)).value.strip != '': tbl.append(template.get(fieldname + str(i)).value.strip) template.remove(fieldname + str(i)) i += 1 if changed: template.add(fieldname + 's', ', '.join(tbl))

so like this is literally all i wrote for this just now