1 # 7. Can you build a list of all of the articles edited by "Benjamin
2 # Mako Hill"? What is the article with the longest title that user
3 # Benjamin Mako Hill has edited?
5 # Step 1: Searching around on Google, I found this documentation which
6 # seemed like the right way to answer this question:
7 # https://www.mediawiki.org/wiki/API:Usercontribs
13 # parameter version which makes a little more sense
14 parameters = {'action' : 'query',
15 'list' : 'usercontribs',
16 'ucuser' : 'Benjamin Mako Hill',
23 wp_call = requests.get('https://en.wikipedia.org/w/api.php', params=parameters)
24 response = wp_call.json()
26 contribs = response['query']['usercontribs']
28 for contrib in contribs:
29 if contrib['title'] not in edited_pages:
30 edited_pages.append(contrib['title'])
32 # keep looping if we need to continue
33 if 'continue' in response:
34 parameters.update(response['continue'])
38 # print out the list of pages
40 for page in edited_pages:
44 print("TOTAL PAGES: %s" % counter)