Last active
August 29, 2015 14:18
-
-
Save marsimaria/bb9f71a0338c038fa272 to your computer and use it in GitHub Desktop.
Britney Spears feat. New York Times
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
| import sys | |
| import re | |
| import json | |
| import random | |
| s = [] | |
| from nytimesarticle import articleAPI | |
| for i in range(0, 100): | |
| api = articleAPI('74548056debe1698254a3a07babc9f84:3:60371965') | |
| res = api.search(q = 'Britney Spears', fq = {'lead_paragraph':'Britney Spears'}, begin_date = 20000101, end_date = 20001231, page = str(i)) | |
| for m in res['response']['docs']: | |
| s.append(m['lead_paragraph']) | |
| with open("britney.txt", "w") as text_file: | |
| for item in s: | |
| text_file.write(item) | |
| britSen = list() | |
| search = r'\b(?:Spears|SPEARS)\b [A-Za-z ]+' | |
| for sentence in open('britney.txt'): | |
| lines = sentence.split('.') | |
| for line in lines: | |
| results = re.findall(search, line) | |
| if len(results) > 0: | |
| britSen.append(results) | |
| # print results | |
| fuckYouOldBritSen = [] | |
| for listbitches in britSen: | |
| listbabes = britSen[0:] | |
| for listbabes in listbitches: | |
| fuckYouOldBritSen.append(listbabes) | |
| # print fuckYouOldBritSen | |
| first = [] | |
| oops = open('oops.txt', 'r') | |
| for sentence in oops: | |
| line = sentence.split('\n') | |
| for eachline in line: | |
| firstword = eachline.split(' ')[0] | |
| firstwords = firstword.strip(',') | |
| if len(firstwords) > 0: | |
| first.append(firstwords) | |
| # print firstwords | |
| for i in range(len(fuckYouOldBritSen)): | |
| r1 = random.choice(first) | |
| r2 = random.choice(fuckYouOldBritSen) | |
| line = r1 + ' '+ r2 | |
| print line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when I try to run a basic api.search command in python 3.4 like you've done here I get the following stack trace. What do you think is causing this?