def main(): global site site = mwclient.Site('en.wikipedia.org') site.login(password.username, password.password) print "Logged in to site; getting template details." global INFOBOX,PARAM,INFOBOX_TITLES INFOBOX = sys.argv[1].replace('_',' ') PARAM = sys.argv[2] INFOBOX_TITLES = [title.strip().lower() for title in bot.redirects(INFOBOX,namespace=10,pg_prefix="Template:",output='page_title')] INFOBOX_TITLES += INFOBOX print "Getting transclusions..." for page in bot.what_transcludes(INFOBOX): page = site.Pages[page['title']] process(page)
def main(): """This defines and fills a global variable for the site, and then runs. """ print "Logging in as " + password.username + "..." global site site = mwclient.Site('en.wikipedia.org') site.login(password.username, password.password) try: global picklefile picklefile = open("bsr_notified.txt", 'r') print picklefile global users_notified users_notified = pickle.load(picklefile) picklefile.close() except (EOFError, IOError, NameError): print "Pickle file was empty...we'll have to make do!" users_notified = [] global to_notify to_notify = {} global picklefile_write picklefile_write = open("bsr_notified.txt", 'w') files = bot.what_transcludes('Bsr') global total_done_now total_done_now = 0 for file in files: x = site.images[file] zam = x.revisions(dir='newer',prop='user') try: rrev = zam.next() except: print file.encode('ascii', 'ignore') + " skipped!" continue zammy = rrev['user'] print "Adding " + file.encode('ascii', 'ignore') + " to " + zammy.encode('ascii', 'ignore') + "'s list now." add_to_dict(zammy,file) print "Now, let's run through those lists." donenow = 5 for key in to_notify: if sokay(donenow) == True: notify(key) donenow = donenow + 1 elif sokay(donenow) == False: pickle.dump(users_notified, picklefile_write) sys.exit() print "All done, pickling." pickle.dump(users_notified, picklefile_write) print "Pickled!"
import difflib # CC-BY-SA Theopolisme # EDIT THIS SUBST_ME = "Infobox Unternehmen" OLD = r"""\{\{""" + SUBST_ME.replace(" ", r"[_ ]") NEW = "{{subst:" + SUBST_ME print OLD, NEW site = mwclient.Site("en.wikipedia.org") site.login(password.main_username, password.main_password) for page in bot.what_transcludes(SUBST_ME): contents = page.edit() newtext = re.sub(OLD, NEW, contents) if contents != newtext: diff = difflib.unified_diff(contents.splitlines(), newtext.splitlines(), lineterm="") print "\n".join(list(diff)) choice = raw_input("[s]ave page or [p]ass?").strip().lower() if choice == "s": page.save(newtext, "Substituting [[Template:Infobox Unternehmen]] (assisted)") else: print "Skipped edit." else: pass # there were no modifications
def main(): """This defines and fills a global variable for the site, and then runs. """ print "Logging in as " + password.username + "..." global site site = mwclient.Site("en.wikipedia.org") site.login(password.username, password.password) global picklefile picklefile = open("users_notified.txt", "r") print picklefile try: global users_notified users_notified = pickle.load(picklefile) except (EOFError): print "Pickle file was empty...we'll have to make do!" users_notified = [] global to_notify to_notify = {} picklefile.close() global picklefile_write picklefile_write = open("users_notified.txt", "w") files = bot.what_transcludes(["Description missing"]) global total_done_now total_done_now = 0 for file in files: # print "Working on " + str(file) x = site.images[file] zam = x.revisions(dir="newer", prop="user") try: rrev = zam.next() except: print file.encode("ascii", "ignore") + " skipped!" continue zammy = rrev["user"] print "Adding " + file.encode("ascii", "ignore") + " to " + zammy.encode("ascii", "ignore") + "'s list now." add_to_dict(zammy, file) print "Now, let's run through those lists." donenow = 5 for key in to_notify: if sokay(donenow) == True: notify(key) donenow = donenow + 1 elif sokay(donenow) == False: pickle.dump(users_notified, picklefile_write) sys.exit() print "All done, pickling." pickle.dump(users_notified, picklefile_write) print "Pickled!"
def main(): """This defines and fills a global variable for the site, and then runs. """ print "Logging in as " + password.username + "..." global site site = mwclient.Site('en.wikipedia.org') site.login(password.username, password.password) try: global picklefile picklefile = open("users_notified.txt", 'r') print picklefile global users_notified users_notified = pickle.load(picklefile) picklefile.close() except (EOFError, IOError, NameError): print "Pickle file was empty...we'll have to make do!" users_notified = [] global to_notify to_notify = {} global picklefile_write picklefile_write = open("users_notified.txt", 'w') files = bot.what_transcludes('Description missing') global total_done_now total_done_now = 0 for file in files: x = site.images[file] zam = x.revisions(dir='newer', prop='user') try: rrev = zam.next() except: print file.encode('ascii', 'ignore') + " skipped!" continue zammy = rrev['user'] print "Adding " + file.encode('ascii', 'ignore') + " to " + zammy.encode( 'ascii', 'ignore') + "'s list now." add_to_dict(zammy, file) print "Now, let's run through those lists." donenow = 5 for key in to_notify: if sokay(donenow) == True: notify(key) donenow = donenow + 1 elif sokay(donenow) == False: pickle.dump(users_notified, picklefile_write) sys.exit() print "All done, pickling." pickle.dump(users_notified, picklefile_write) print "Pickled!"