Skip to content

Instantly share code, notes, and snippets.

@ahurriyetoglu
Last active November 1, 2015 03:32
Show Gist options
  • Save ahurriyetoglu/23c10d9610fafabee3c7 to your computer and use it in GitHub Desktop.
Save ahurriyetoglu/23c10d9610fafabee3c7 to your computer and use it in GitHub Desktop.
# Docs: http://open-platform.theguardian.com/documentation/
import requests as r
import json
g_api_key = "Your API key" # limit is 12 calls per second.
keyterm = "Your Keyterm"
#from-date=1920-
g_articles_strt = r.get("http://content.guardianapis.com/search?q="+keyterm+"/politics&show-blocks=all&from-date=2015-01-01&api-key="+g_api_key)
g_articles_list = []
print(g_articles_strt.json()["response"]["pages"]) # get available pages
for p in range(1,g_articles_strt.json()["response"]["pages"]+2): # iterate over the pages
g_articles = r.get("http://content.guardianapis.com/search?q=rohingya/politics&show-blocks=all&page="+str(p)+"&from-date=1920-01-01&api-key="+g_api_key)
g_articles_list += g_articles.json()["response"]["results"] # put all the results in one list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment