Created
November 8, 2012 12:05
-
-
Save bruntonspall/4038400 to your computer and use it in GitHub Desktop.
Get star ratings from the guardian content api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
baseUrl="http://content.guardianapis.com/search?tag=tone%2Freviews§ion=technology&format=json&show-fields=starRating" | |
pagef="&page=%d" | |
for i in range(200): | |
j = json.loads(''.join(urllib2.urlopen(baseUrl+pagef % (i+1)).readlines())) | |
reviews = [(item['id'],item['fields'].get('starRating')) for item in j['response']['results'] if item['fields'].get('starRating')] | |
for id,rating in reviews: | |
d[rating] = d.get(rating, []) + [id] | |
sorted([(k, len(v)) for k,v in d.items()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment