Created
April 1, 2016 18:39
-
-
Save nicolehe/5943a8beb734b5bee5c874eb3a98f6d0 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 sys | |
import urllib | |
import json | |
import random | |
from nltk.tokenize import sent_tokenize, word_tokenize | |
pet_params = { | |
'format': 'json', | |
'output': 'full', | |
'key': '63703cf6c3d40b73af4e939adda7da4f', | |
} | |
pet_url_path = "http://api.petfinder.com/pet.getRandom?&" | |
pet_query_s = urllib.urlencode(pet_params) | |
pet_url = pet_url_path + pet_query_s | |
pet_raw = urllib.urlopen(pet_url).read() | |
pet_data = json.loads(pet_raw) | |
pet_description_raw = pet_data['petfinder']['pet']['description']['$t'] | |
pet_name = pet_data['petfinder']['pet']['name']['$t'] | |
print pet_name | |
pet_lines = sent_tokenize(pet_description_raw) | |
NYT_search = pet_name | |
NYT_url = "http://api.nytimes.com/svc/search/v2/articlesearch.json?q=" + NYT_search + "&page=1" + "&api-key=6d5aabe72e059f4df7f6b330adc30b66%3A11%3A45505059" | |
NYT_raw = urllib.urlopen(NYT_url).read() | |
NYT_data = json.loads(NYT_raw) | |
NYT_para_raw = NYT_data['response']['docs'][0]['lead_paragraph'] | |
NYT_lines = sent_tokenize(NYT_para_raw) | |
print pet_lines[0] | |
print NYT_lines[0] | |
print pet_lines[1] | |
print NYT_lines[1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment