Skip to content

Instantly share code, notes, and snippets.

@coblezc
Last active April 4, 2016 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coblezc/5dd3c26f3122a1e57c3070a2ec88d13b to your computer and use it in GitHub Desktop.
Save coblezc/5dd3c26f3122a1e57c3070a2ec88d13b to your computer and use it in GitHub Desktop.
# 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