initial import of solutions for wikipedia data challenges
[wikipedia-cdsw-solutions] / solution_2.py
1 # 2. Print out the revision ids and edit summaries (i.e., comment) of each revision for the article on Python.
2
3 import requests
4
5 # parameter version which makes a little more sense
6 parameters = {'action' : 'query',
7               'prop' : 'revisions',
8               'titles' : 'Python (programming language)',
9               'rvlimit' : 100,
10               # changed this line to add ids|comment
11               'rvprop' : "ids|comment",
12               'format' : 'json',
13               'continue' : ''}
14
15 # run a "while True" loop
16 while True:
17     wp_call = requests.get('https://en.wikipedia.org/w/api.php', params=parameters)
18     response = wp_call.json()
19     
20     for page_id in response["query"]["pages"].keys():
21         revisions = response["query"]["pages"][page_id]["revisions"]
22         
23         for rev in revisions:
24             # changed this line to add revid and comment
25             print(str(rev["revid"]) + "\t" + rev["comment"])
26
27     if 'continue' in response:
28         parameters.update(response['continue'])
29     else:
30         break
31             

Benjamin Mako Hill || Want to submit a patch?