Last active
April 4, 2016 02:09
-
-
Save coblezc/5dd3c26f3122a1e57c3070a2ec88d13b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# hw3 for rwet | |
import urllib | |
import json | |
import random | |
nouns_data = urllib.urlopen("https://raw.githubusercontent.com/dariusk/corpora/master/data/words/nouns.json").read() | |
noun_json = json.loads(nouns_data) | |
url = "http://api.nytimes.com/svc/books/v3/lists/combined-print-and-e-book-fiction.json?&api-key=๐" | |
data = urllib.urlopen(url).read() | |
load_titles = json.loads(data) | |
titles = list() | |
for books in load_titles['results']['books']: | |
title = books['title'] | |
titles.append(title.lower()) | |
# new_tokens = list() | |
for title in titles: | |
print 'BEST SELLER: ', title.title() | |
tokens = title.split() | |
new_title = list() | |
for token in tokens: | |
# print 'token: ', token | |
url = "http://api.wordnik.com:80/v4/word.json/" + token + "/definitions?limit=200&includeRelated=true&useCanonical=false&includeTags=false&api_key=๐" | |
raw_data = urllib.urlopen(url).read() | |
data = json.loads(raw_data) | |
for thing in data: | |
pos = data[0]['partOfSpeech'] | |
if pos == 'noun': | |
new_title.append(random.choice(noun_json['nouns'])) | |
else: | |
new_title.append(token) | |
break | |
the_new_title = ' '.join(new_title) | |
print 'WORST SELLER: ', the_new_title.upper() + '\n' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment