Skip to content

Instantly share code, notes, and snippets.

@bruntonspall
Created November 8, 2012 12:05
Show Gist options
  • Save bruntonspall/4038400 to your computer and use it in GitHub Desktop.
Save bruntonspall/4038400 to your computer and use it in GitHub Desktop.
Get star ratings from the guardian content api
baseUrl="http://content.guardianapis.com/search?tag=tone%2Freviews&section=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