Last active
February 26, 2020 20:41
-
-
Save RheingoldRiver/d87bcbf369831384bff8111340c3c9fc 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
from mwclient import Site | |
limit = -1 | |
site = Site('https://lol.gamepedia.com', path="/") # Set wiki | |
site.login('RheingoldRiver@BotPasswordName', 'smldrgsrthmldyhj') | |
revisions = 2 # numver of revisions to roll back | |
comment = None # require the comment on the edit you're rolling back to be this | |
print(comment) | |
comment = "fixing toggle" | |
with open('pages.txt', encoding="utf-8") as f: | |
pages = f.readlines() | |
pages = [page.strip() for page in pages] | |
lmt = 0 | |
for page in pages: | |
if lmt == limit: | |
break | |
lmt += 1 | |
data = site.api('query', | |
format = 'json', | |
prop = 'revisions', | |
titles = page, | |
rvprop = 'content|comment', | |
rvlimit = revisions + 1 | |
) | |
datapages = data['query']['pages'] | |
text = '' | |
print(page) | |
make_edit = comment | |
for pg in datapages: | |
# revisions is 1-indexed, but the api response is 0-indexed | |
if comment: | |
make_edit = datapages[pg]['revisions'][revisions-1]['comment'] == comment | |
print(pg) | |
text = datapages[pg]['revisions'][revisions]['*'] | |
if make_edit: | |
p = site.pages[page] | |
p.save(text,'Reverting oops') | |
else: | |
print("Skipping page %s because comment doesn't match" % page) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment