Reading & Writing Electronic Text: "Tweet York Times"

For my final RWET project, I wanted to further explore a previous project of mashing up news stories with tweets. I thought it would be interested to create a piece that encompassed the full scope of emotions around a particular issue, by using lines from a NY Times article (for the more removed end of the emotional spectrum), and Tweets (for the less removed end).

Output

The results looked like this:

A 243-page investigative report could have been boiled down to a single sentence: Tom Brady — one the most accomplished N.F.L. quarterbacks ever — is, more probably than not, a cheater, said the NY Times.

#TomBrady its time 2 be a man! U not only knew about this cheating. U lied about it, and tried to cover it up Come clean! #DeflateGate #NFL, said  @SPORTalkYankees on Thu May 07 14:37:55.

After the release of a critical report detailing the Patriots’ apparent deflation of footballs, Goodell must determine punishment for the team and its star, Tom Brady, said the NY Times.

So #TomBrady wouldn't turn over emails or text messages for investigation. He clearly has a future in politics after #NFL career is over., said  @cpfuchs on Thu May 07 14:35:29.

Tom Brady smiled away the Tuck Rule on the way to his first Super Bowl victory, flashing that dimple-chinned grin that said, "I had it all the time,” said the NY Times.

That #TomBrady. Movie star handsome, married a supermodel, always says the right thing, perennial winner. What's not to hate? #DeflateGate, said @mallardNB on Thu May 07 14:35:11.

An NFL investigation has found that New England Patriots employees likely deflated footballs and that quarterback Tom Brady was "at least generally aware" of the rules violations, said the NY Times.

I can't stand playing football with my son in the backyard when he pretends to be #TomBrady  (exhale) #DeflateGate, said  @Bookgirl6 on Thu May 07 14:34:50.

The @nfl has suspended people for a lot less than what #TomBrady and #BeliCheat have done this time. #Forfeit the trophy., said  @MrsSmeej on Thu May 07 14:37:31.

Ted Wells’s report, released on Wednesday, found that “it is more probable than not” that Patriots personnel deflated the footballs in the A.F.C. championship game to gain an edge, said the NY Times.

The output was pretty interesting to me, and represented this strange division between the way we feel and the manner in which we've been conditioned to write. It was fun to perform it, and I think that reading it aloud really gives it the personality it deservers. The challenge there was mimicking the journalistic tone (think "From New York City, this is Michael Weber, ABC News), and the more emotional tone of the sportfans' angry tweets.

Programming

To create the program I used the NY Times and Twitter API, as well as the Twython library to parse the incoming data from Twitter. I then took the first few lines of each paragraph in the Times pertaining to "Tom Brady" for the previous 24-hours, and tweets with the hashtag #Tom Brady.

I inserted the Times lines and the Tweets into separate lists, then pulled randomly from each of those lists and alternated the output.

And the code, here:

import urllib2
import json
import random


#---------
#NYTIMES
#---------
#API setup
response = urllib2.urlopen('http://api.nytimes.com/svc/search/v2/articlesearch.json?q=Tom+Brady&begin_date=20150506&api-key=471e09ee05c919516a6f1f7973c5ad03%3A16%3A58416624').read()

data = json.loads(response)

response_structure = data["response"]
docs_list = response_structure["docs"]

nyTimesLeads = [] #create list of lead paragraphs
nyTimesAbstracts = [] #create list of lead paragraphs

#grab lead_paragraph        
for item in docs_list:
    if "lead_paragraph" in item:
        nyTimesLeads.append(item["lead_paragraph"])
        print nyTimesLeads
        
        

        
#---------
#Twitter
#---------            

#API setup
import twython

#Get from https://apps.twitter.com/app/8037305/keys:
twitter = twython.Twython("oDtjPPOsBuTpR4SReeQ6fTswZ", "BZqpzpF1gPO6OXZ9tzlZQl5rHLN5muPvGRH5fzTXwxSVcM7x3x", "25921506-vxdQM2M66ad3ZRen1OBdWmGLrLXw91xoHqn9v14TS", "FA4HK1NxILLRHa50NYsU8Cqcgi59LygV7QFKtbDqBPvka")

twitterQuotesUser = [] #create list of Twitter quotes from search results
twitterQuotesTweet = []    
        
#Search Results        
try:
    search_results = twitter.search(q='tombrady', count=100)
except TwythonError as e:
    print e

#Grab username and time in twitterQuotesUser, and tweet into twitterQuotesTweet
for tweet in search_results['statuses']:
        twitterQuotesUser.append(' @%s on Date: %s' %(tweet['user']['screen_name'].encode('utf-8'), tweet['created_at']))
        twitterQuotesTweet.append(tweet['text'].encode('utf-8'))         

print twitterQuotesTweet
#---------
#Output
#---------    
#TWITTER CONTSTRUCT
#**print them together
twitterQuotesUserRandomOne = random.choice(twitterQuotesUser)
twitterQuotesTweetRandomOne = random.choice(twitterQuotesTweet)
twitterQuotesUserRandomTwo = random.choice(twitterQuotesUser)
twitterQuotesTweetRandomTwo = random.choice(twitterQuotesTweet)

twitterFullQuoteOne = twitterQuotesTweetRandomOne + ", said " + twitterQuotesUserRandomOne + ", about allegations against Tom Brady." 
twitterFullQuoteTwo = twitterQuotesTweetRandomTwo + ", said " + twitterQuotesUserRandomTwo + ", about allegations against Tom Brady."

 

#NYTIMES CONSTRUCT
#Lead paragraph
nyTimesLeadSampleOne = random.choice(nyTimesLeads)
nyTimesLeadSampleTwo = random.choice(nyTimesLeads)    

    

#Combo
outputComboLead = nyTimesLeadSampleOne + twitterFullQuoteOne + nyTimesLeadSampleTwo + twitterFullQuoteTwo


#*****
print outputComboLead 
#*****