]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/api.revisions.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / api.revisions.py
1 """
2 Prints the rev_id, characters and hash of all revisions to User:EpochFail.
3 """
4 import sys
5 import os
6
7 sys.path.insert(0, os.path.abspath(os.getcwd()))
8
9 import hashlib
10 from mw import api
11
12 api_session = api.Session("https://en.wikipedia.org/w/api.php")
13
14 revisions = api_session.revisions.query(
15     properties={'ids', 'content'},
16     titles={"User:EpochFail"},
17     direction="newer",
18     limit=51
19 )
20
21 for rev in revisions:
22     print(
23         "{0} ({1} chars): {2}".format(
24             rev['revid'],
25             len(rev.get('*', "")),
26             hashlib.sha1(bytes(rev.get('*', ""), 'utf8')).hexdigest()
27         )
28     )

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