Created
March 25, 2015 18:49
-
-
Save katsully/36f0338fa0b41d088db0 to your computer and use it in GitHub Desktop.
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
import requests | |
from random import randint | |
counter = 0 | |
term = "Right-Wing" | |
while counter < 20: | |
r = requests.get('http://api.nytimes.com/svc/search/v2/articlesearch.json?fq=headline:(' + term + ')&api-key=8507eaad79faa9ac49204db270a8e0e3:13:70195569') | |
if r.ok == False: | |
break | |
data = r.json() | |
docs = data['response']['docs'] | |
found_article = False | |
headline = "" | |
for doc in docs: | |
headline = doc['headline']['main'] | |
if headline.rsplit(' ')[0] == term: | |
found_article = True | |
break | |
counter2 = 1 | |
while found_article is False: | |
r = requests.get('http://api.nytimes.com/svc/search/v2/articlesearch.json?fq=headline:(' + term + ')&page='+str(counter2)+'&api-key=8507eaad79faa9ac49204db270a8e0e3:13:70195569') | |
if r.ok == False: | |
break | |
data = r.json() | |
docs = data['response']['docs'] | |
found_article = False | |
headline = "" | |
for doc in docs: | |
headline = doc['headline']['main'] | |
if headline.rsplit(' ')[0] == term: | |
found_article = True | |
break | |
counter2 += 1 | |
if counter2 > 15 : | |
break | |
if found_article is False: | |
break | |
print headline.encode('utf-8') | |
term = headline.rsplit(' ')[-1] | |
if term.find('-') !=-1: | |
term = term.rsplit('-')[-1] | |
counter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment