initial import of solutions for wikipedia data challenges
[wikipedia-cdsw-solutions] / solution_6.py
1 # 6. How would you use the API to find out how many revisions/edits the user "Benjamin Mako Hill" has made to Wikipedia?
2
3 # I found documentation here: https://www.mediawiki.org/wiki/API:Users
4
5 import requests
6
7 # parameter version which makes a little more sense
8 parameters = {'action' : 'query',
9               'list' : 'users',
10               'ususers' : 'Benjamin Mako Hill',
11               'usprop' : 'editcount',
12               'format' : 'json' }
13
14 wp_call = requests.get('https://en.wikipedia.org/w/api.php', params=parameters)
15 response = wp_call.json()
16
17 print(response['query']['users'][0]['editcount'])

Benjamin Mako Hill || Want to submit a patch?