]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/api.deleted_revisions.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / api.deleted_revisions.py
1 """
2 Prints the rev_id, characters and hash of all revisions to Willy_on_Wheels.
3 """
4 import getpass
5 import hashlib
6 import os
7 import sys
8
9 try:
10     sys.path.insert(0, os.path.abspath(os.getcwd()))
11
12     from mw import api
13 except: raise
14
15
16
17 api_session = api.Session("https://en.wikipedia.org/w/api.php")
18
19 print("(EN) Wikipedia credentials...")
20 username = input("Username: ")
21 password = getpass.getpass("Password: ")
22 api_session.login(username, password)
23
24 revisions = api_session.deleted_revisions.query(
25     properties={'ids', 'content'},
26     titles={'Willy on Wheels'},
27     direction="newer"
28 )
29
30 for rev in revisions:
31     print(
32         "{0} ({1} chars): {2}".format(
33             rev['revid'],
34             len(rev.get('*', "")),
35             hashlib.sha1(bytes(rev.get('*', ""), 'utf8')).hexdigest()
36         )
37     )

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