]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/lib.reverts.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / lib.reverts.py
1 """
2 Prints all reverted revisions of User:EpochFail.
3 """
4 from mw.api import Session
5 from mw.lib import reverts
6
7 # Gather a page's revisions from the API
8 api_session = Session("https://en.wikipedia.org/w/api.php")
9 revs = api_session.revisions.query(
10     titles={"User:EpochFail"},
11     properties={'ids', 'sha1'},
12     direction="newer"
13 )
14
15 # Creates a revsion event iterator
16 rev_events = ((rev['sha1'], rev) for rev in revs)
17
18 # Detect and print reverts
19 for revert in reverts.detect(rev_events):
20     print("{0} reverted back to {1}".format(revert.reverting['revid'],
21                                             revert.reverted_to['revid']))

Community Data Science Collective || Want to submit a patch?