summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f2892ae)
- move to Python 3 (i.e., print()'ify stuff)
- requests can do JSON natively using .json() on the request object which
solves the problem with requests returning bytes
import requests
wp_call = requests.get('https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main_Page&rvlimit=100&rvprop=timestamp|user&format=json')
import requests
wp_call = requests.get('https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main_Page&rvlimit=100&rvprop=timestamp|user&format=json')
-response = json.loads(wp_call.content)
+response = wp_call.json()
for page_id in response["query"]["pages"].keys():
page_title = response["query"]["pages"][page_id]["title"]
revisions = response["query"]["pages"][page_id]["revisions"]
for rev in revisions:
for page_id in response["query"]["pages"].keys():
page_title = response["query"]["pages"][page_id]["title"]
revisions = response["query"]["pages"][page_id]["revisions"]
for rev in revisions:
- print page_title + "\t" + rev["user"] + "\t" + rev["timestamp"]
+ print(page_title + "\t" + rev["user"] + "\t" + rev["timestamp"])
import requests
url_base = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=%s&rvlimit=100&rvprop=timestamp|user&format=json'
import requests
url_base = 'https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=%s&rvlimit=100&rvprop=timestamp|user&format=json'
for page_title in pages:
wp_call = requests.get(url_base % page_title)
for page_title in pages:
wp_call = requests.get(url_base % page_title)
- response = json.loads(wp_call.content)
+ response = wp_call.json()
for page_id in response["query"]["pages"].keys():
page_title = response["query"]["pages"][page_id]["title"]
revisions = response["query"]["pages"][page_id]["revisions"]
for rev in revisions:
for page_id in response["query"]["pages"].keys():
page_title = response["query"]["pages"][page_id]["title"]
revisions = response["query"]["pages"][page_id]["revisions"]
for rev in revisions:
- print page_title + "\t" + rev["user"] + "\t" + rev["timestamp"]
-
+ print(page_title + "\t" + rev["user"] + "\t" + rev["timestamp"])