]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/api.recent_changes.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / api.recent_changes.py
1 """
2 Prints the rev_id and hash of the 10 oldest edits in recent_changes.
3 """
4 import os
5 import sys
6
7 try:
8     sys.path.insert(0, os.path.abspath(os.getcwd()))
9     from mw import api
10 except:
11     raise
12
13 api_session = api.Session("https://en.wikipedia.org/w/api.php")
14
15 changes = api_session.recent_changes.query(
16     type={'edit', 'new'},
17     properties={'ids', 'sha1', 'timestamp'},
18     direction="newer",
19     limit=10
20 )
21
22 for change in changes:
23     print(
24         "{0} ({1}) @ {2}: {3}".format(
25             change['rcid'],
26             change['type'],
27             change['timestamp'],
28             change.get('sha1', "")
29         )
30     )

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