Wednesday, September 18, 2019

Import Tweets using tweepy

TweetPython

This is a code piece using which you can import tweets.

Step1: Set-up your twitter acount and get your twitter credentials and save them in a file called cred.py. That should contain

ckey,csecret,atoken and asecret whihc will be used for authentication purpose.

Step2: install tweepy package

Now you can execute this code which will fetch tweets and save in CSV. In this sample code I am trying to import

tweets from Donald Trump's tweet handle and changing a few lines you can able to import all the tweets which

mentioned Article 370

In [131]:
#Import librabry
import tweepy
from tweepy import API
from tweepy import Cursor
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import cred
import pandas as pd
from tabulate import tabulate
import csv


class TwitterAuthenticator():
    def authenticate_twitter_app(self):        
        auth = OAuthHandler(cred.ckey, cred.csecret)
        auth.set_access_token(cred.atoken, cred.asecret)
        return auth

class TwitterStreamer():
    """
    Class for streaming and processing live tweets
    """
    def __init__(self):
        self.twitter_authenticator=TwitterAuthenticator()
    def stream_tweets(self, tweets_filename,hashtaglist):
        #This handles twitter authentication and the connection to the Twitter streaming API.
        listener=TwitterListener(tweets_filename)
        auth=self.twitter_authenticator.authenticate_twitter_app()
        #twitterStream = Stream(auth, listener)
        #Filtering the tweets we want to analyse
        #twitterStream.filter(track=hashtaglist)
        
        api = tweepy.API(auth) 
  
        # 200 tweets to be extracted 
        #number_of_tweets=2000
        tweets = api.user_timeline(screen_name="realDonaldTrump",count=10000) 
        cols = ['id', 'created_at', 'text', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'retweeted',
                'retweet_count', 'favorited', 'favorite_count', 'source']

        tweet = [[getattr(t, x) for x in cols] for t in tweets]
        print(tweet)
        ids=[]
        created_at=[]
        text=[]
        for row in tweet:
            ids.append(row[0])
            created_at.append(row[1])
            text.append(row[2])
            
        #print(ids)
        #print(created_at)
        #print(text)
        
        #final=ids+created_at+text
        #print(final)
        table = pd.DataFrame(list(zip(ids,created_at,text)), columns=['id', 'created_at', 'text'])
        print(table)
        table.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\TrumpTweets.csv')
        #tweet.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\a.csv')
        
class TwitterListener(StreamListener):#Inherited from StreamListener
    """
    Basic listner class to print and save the tweeets.
    """
    def __init__(self,tweets_filename):
        self.tweets_filename=tweets_filename
    def on_data(self, data): #Overridding class
        try:
            with open(self.tweets_filename,'a') as tf:
                tf.write(data)
            print(data)
            return True
        except BaseException as e:
            print("Error on_data: %s" %str(e))
            return True
    def on_error(self, status):
        if status==420:            
            #Return false on_data merhod in case we breach limits
            return False
        print(status)

if __name__=="__main__":# confirms that the code is under main function
    hashtaglist=["Article 370"]
    tweets_filename="tweet.json"
    ts=TwitterStreamer()
    ts.stream_tweets(tweets_filename,hashtaglist)
[[1171760702564052993, datetime.datetime(2019, 9, 11, 12, 21, 36), 'Leaving the White House soon to speak at the Pentagon. My great honor!', None, None, False, 3609, False, 19982, 'Twitter for iPhone'], [1171760235935125508, datetime.datetime(2019, 9, 11, 12, 19, 45), 'If it weren’t for the never ending Fake News about me, and with all that I have done (more than any other President… https://t.co/2MiOiqnA0v', None, None, False, 3472, False, 15167, 'Twitter for iPhone'], [1171758532280143873, datetime.datetime(2019, 9, 11, 12, 12, 58), '....This is a phony suppression poll, meant to build up their Democrat partners. I haven’t even started campaigning… https://t.co/wSiokMjuVd', 'realDonaldTrump', 1171758531449643008, False, 3343, False, 14910, 'Twitter for iPhone'], [1171758531449643008, datetime.datetime(2019, 9, 11, 12, 12, 58), 'In a hypothetical poll, done by one of the worst pollsters of them all, the Amazon Washington Post/ABC, which predi… https://t.co/4rzAjxXKWq', None, None, False, 3564, False, 15751, 'Twitter for iPhone'], [1171743257589690370, datetime.datetime(2019, 9, 11, 11, 12, 17), 'RT @AndrewPollackFL: Broward schools put this MONSTER in class with my beautiful daughter. \n\nThey knew exactly what he was. They gave him a…', None, None, False, 11145, False, 0, 'Twitter for iPhone'], [1171742213027586049, datetime.datetime(2019, 9, 11, 11, 8, 8), 'RT @MariaBartiromo: https://t.co/yMq3Eyiw7O @MorningsMaria @FoxBusiness', None, None, False, 1688, False, 0, 'Twitter for iPhone'], [1171741981703311360, datetime.datetime(2019, 9, 11, 11, 7, 13), 'RT @MariaBartiromo: China is moving to develop a more level playing field: Sen. Perdue https://t.co/97UZWyhiJu  @MorningsMaria @FoxBusiness', None, None, False, 1706, False, 0, 'Twitter for iPhone'], [1171738781025746945, datetime.datetime(2019, 9, 11, 10, 54, 29), 'RT @realDonaldTrump: Greg Murphy won big, 62% to 37%, in North Carolina 03, & the Fake News barely covered the race. The win was far bigger…', None, None, False, 10644, False, 0, 'Twitter for iPhone'], [1171736398212272128, datetime.datetime(2019, 9, 11, 10, 45, 1), 'RT @realDonaldTrump: BIG NIGHT FOR THE REPUBLICAN PARTY. CONGRATULATIONS TO ALL!', None, None, False, 14639, False, 0, 'Twitter for iPhone'], [1171735692428419072, datetime.datetime(2019, 9, 11, 10, 42, 13), '....The USA should always be paying the the lowest rate. No Inflation! It is only the naïveté of Jay Powell and the… https://t.co/0kHSVfJK8m', 'realDonaldTrump', 1171735691769929728, False, 5109, False, 21306, 'Twitter for iPhone'], [1171735691769929728, datetime.datetime(2019, 9, 11, 10, 42, 13), 'The Federal Reserve should get our interest rates down to ZERO, or less, and we should then start to refinance our… https://t.co/lWeTPNNS4i', None, None, False, 6597, False, 25810, 'Twitter for iPhone'], [1171733174101131264, datetime.datetime(2019, 9, 11, 10, 32, 13), 'https://t.co/WqBj8iMQhx', None, None, False, 21309, False, 83506, 'Twitter for iPhone'], [1171728799408500737, datetime.datetime(2019, 9, 11, 10, 14, 50), '“China suspends Tariffs on some U.S. products. Being hit very hard, supply chains breaking up as many companies mov… https://t.co/Y0BHEiyt3k', None, None, False, 5469, False, 5873, 'Twitter for iPhone'], [1171651786622537728, datetime.datetime(2019, 9, 11, 5, 8, 48), 'Greg Murphy won big, 62% to 37%, in North Carolina 03, & the Fake News barely covered the race. The win was far big… https://t.co/LUV9RwS0Yt', None, None, False, 10644, False, 43023, 'Twitter for iPhone'], [1171642393583656961, datetime.datetime(2019, 9, 11, 4, 31, 29), 'Alice @alicetweet Stewart: Thank you for the nice words while on @CNN concerning the TWO big Republican Congression… https://t.co/wHBvNj5k9G', None, None, False, 5924, False, 27842, 'Twitter for iPhone'], [1171631144414208000, datetime.datetime(2019, 9, 11, 3, 46, 47), 'https://t.co/eK7swFWq1A', None, None, False, 17415, False, 77253, 'Twitter for iPhone'], [1171629221552283648, datetime.datetime(2019, 9, 11, 3, 39, 8), 'RT @kevinomccarthy: GOP 2, Democrats 0 \n\nRevolution not retirements. Congrats Dan Bishop and Dr. Greg Murphy!\n\nWell done @NRCC, @GOP and @N…', None, None, False, 7782, False, 0, 'Twitter for iPhone'], [1171622285507289088, datetime.datetime(2019, 9, 11, 3, 11, 35), '.@CNN & @MSNBC were all set to have a BIG victory, until Dan Bishop won North Carolina 09. Now you will hear them b… https://t.co/n5XUdxU6ys', None, None, False, 10330, False, 39123, 'Twitter for iPhone'], [1171614032782123008, datetime.datetime(2019, 9, 11, 2, 38, 47), 'BIG NIGHT FOR THE REPUBLICAN PARTY. CONGRATULATIONS TO ALL!', None, None, False, 14639, False, 72296, 'Twitter for iPhone'], [1171613145523195904, datetime.datetime(2019, 9, 11, 2, 35, 16), 'Greg Murphy is a big winner in North Carolina 03. Much bigger margins than originally anticipated. Congratulations Greg!', None, None, False, 9038, False, 45090, 'Twitter for iPhone'], [1171611976100917248, datetime.datetime(2019, 9, 11, 2, 30, 37), 'Dan Bishop was down 17 points 3 weeks ago. He then asked me for help, we changed his strategy together, and he ran… https://t.co/qM6JXNZuMw', None, None, False, 10263, False, 45304, 'Twitter for iPhone'], [1171595113673347072, datetime.datetime(2019, 9, 11, 1, 23, 36), 'Senator Ben Sasse has done a wonderful job representing the people of Nebraska. He is great with our Vets, the Mili… https://t.co/hTZIlHniy1', None, None, False, 9365, False, 38159, 'Twitter for iPhone'], [1171590284544827392, datetime.datetime(2019, 9, 11, 1, 4, 25), 'I am pleased to endorse Governor Mike Parson of Missouri. He is very Popular, Strong, and knows what he is doing –… https://t.co/oWqrcV5znu', None, None, False, 11557, False, 49135, 'Twitter for iPhone'], [1171586554281615360, datetime.datetime(2019, 9, 11, 0, 49, 36), 'Excellent interview by @CondoleezzaRice on @MarthaMaccallum on @FoxNews. Very interesting and secure perspective on life.', None, None, False, 6326, False, 29167, 'Twitter for iPhone'], [1171586230628311045, datetime.datetime(2019, 9, 11, 0, 48, 19), 'One down, one to go – Greg Murphy is projected to win in the Great State of North Carolina! #NC03', None, None, False, 8546, False, 40141, 'Twitter for iPhone'], [1171547046295171072, datetime.datetime(2019, 9, 10, 22, 12, 36), 'Incredible progress being made at the Southern Border! https://t.co/xcqxKEkfGD', None, None, False, 11632, False, 45073, 'Twitter for iPhone'], [1171475308416884739, datetime.datetime(2019, 9, 10, 17, 27, 33), 'RT @realDonaldTrump: Vote today for Dan Bishop. Will be great for North Carolina and our Country!', None, None, False, 12115, False, 0, 'Twitter for iPhone'], [1171475286170292224, datetime.datetime(2019, 9, 10, 17, 27, 27), 'RT @realDonaldTrump: NORTH CAROLINA, VOTE FOR DAN BISHOP TODAY. WE NEED HIM BADLY IN WASHINGTON!', None, None, False, 15710, False, 0, 'Twitter for iPhone'], [1171475240322383873, datetime.datetime(2019, 9, 10, 17, 27, 16), 'RT @realDonaldTrump: Last night in North Carolina was incredible! https://t.co/bEfd1v77Nf', None, None, False, 11792, False, 0, 'Twitter for iPhone'], [1171452881729228802, datetime.datetime(2019, 9, 10, 15, 58, 26), '....I asked John for his resignation, which was given to me this morning. I thank John very much for his service. I… https://t.co/d3xTEZySNk', 'realDonaldTrump', 1171452880055746560, False, 16986, False, 71633, 'Twitter for iPhone'], [1171452880055746560, datetime.datetime(2019, 9, 10, 15, 58, 25), 'I informed John Bolton last night that his services are no longer needed at the White House. I disagreed strongly w… https://t.co/P9awoBGUZs', None, None, False, 26574, False, 95341, 'Twitter for iPhone'], [1171439301826994176, datetime.datetime(2019, 9, 10, 15, 4, 28), 'Vote today for Dan Bishop. Will be great for North Carolina and our Country!', None, None, False, 12115, False, 49811, 'Twitter for iPhone'], [1171431074485817344, datetime.datetime(2019, 9, 10, 14, 31, 46), 'One of the greatest and most powerful weapons used by the Fake and Corrupt News Media is the phony Polling Informat… https://t.co/RWGDwmZFgE', None, None, False, 16812, False, 66225, 'Twitter for iPhone'], [1171429005251104769, datetime.datetime(2019, 9, 10, 14, 23, 33), 'ABC/Washington Post Poll was the worst and most inaccurate poll of any taken prior to the 2016 Election. When my la… https://t.co/d0X5jSqcyG', None, None, False, 11241, False, 49145, 'Twitter for iPhone'], [1171413029264732160, datetime.datetime(2019, 9, 10, 13, 20, 4), 'NORTH CAROLINA, VOTE FOR DAN BISHOP TODAY. WE NEED HIM BADLY IN WASHINGTON!', None, None, False, 15710, False, 61204, 'Twitter for iPhone'], [1171404283541164032, datetime.datetime(2019, 9, 10, 12, 45, 19), 'RT @Scavino45: 🚨Happening Now—\n@POTUS @realDonaldTrump departing the @WhiteHouse for North Carolina.... https://t.co/HtreybGIAc', None, None, False, 3357, False, 0, 'Twitter for iPhone'], [1171404220781793282, datetime.datetime(2019, 9, 10, 12, 45, 4), 'RT @IvankaTrump: In August, the African American unemployment rate fell to a historic low of 5.5 %. \nAfrican American women are benefiting…', None, None, False, 6313, False, 0, 'Twitter for iPhone'], [1171404116733640709, datetime.datetime(2019, 9, 10, 12, 44, 39), 'RT @realDonaldTrump: Received an update on Air Force One at MCAS Cherry Point in North Carolina, regarding damage caused by Hurricane Doria…', None, None, False, 6736, False, 0, 'Twitter for iPhone'], [1171403919651680258, datetime.datetime(2019, 9, 10, 12, 43, 52), 'RT @mike_pence: Thrilled to be here in the great state of North Carolina with a man who has been fighting every day to keep the promises he…', None, None, False, 3997, False, 0, 'Twitter for iPhone'], [1171403844707913729, datetime.datetime(2019, 9, 10, 12, 43, 34), 'RT @mike_pence: It has been two and a half years of promises made and promises kept which is why we need FOUR MORE YEARS of President @real…', None, None, False, 7123, False, 0, 'Twitter for iPhone'], [1171403726462029825, datetime.datetime(2019, 9, 10, 12, 43, 6), 'RT @mike_pence: Here in North Carolina, we believed you could be strong again and we believed you could be prosperous again. You said yes t…', None, None, False, 3667, False, 0, 'Twitter for iPhone'], [1171403572606464001, datetime.datetime(2019, 9, 10, 12, 42, 29), 'RT @IvankaTrump: Great to be w/ +175 leaders from gov, industry & academia for the @WhiteHouse #AIinGovSummit to highlight innovative effor…', None, None, False, 3665, False, 0, 'Twitter for iPhone'], [1171403455870771209, datetime.datetime(2019, 9, 10, 12, 42, 2), 'RT @IvankaTrump: The Alabama Success story:\n\nSince the Trump election..\n\n👍🏻The unemployment rate has fallen 2.5% and reached an all time lo…', None, None, False, 9835, False, 0, 'Twitter for iPhone'], [1171403417551589382, datetime.datetime(2019, 9, 10, 12, 41, 53), 'RT @realDonaldTrump: THANK YOU Fayetteville, North Carolina! Make sure you get out and VOTE TOMORROW for Dan Bishop in #NC09 and Greg Murph…', None, None, False, 14265, False, 0, 'Twitter for iPhone'], [1171403341492097024, datetime.datetime(2019, 9, 10, 12, 41, 34), 'Last night in North Carolina was incredible! https://t.co/bEfd1v77Nf', None, None, False, 11792, False, 49419, 'Twitter for iPhone'], [1171403065540390912, datetime.datetime(2019, 9, 10, 12, 40, 29), 'Great job by the U.S. Coast Guard! https://t.co/MhJZgN0Yqc', None, None, False, 5438, False, 28180, 'Twitter for iPhone'], [1171254828456194049, datetime.datetime(2019, 9, 10, 2, 51, 26), 'THANK YOU @USCG! GREAT JOB!! https://t.co/eEDn760Ogh', None, None, False, 10155, False, 46129, 'Twitter for iPhone'], [1171240579642089473, datetime.datetime(2019, 9, 10, 1, 54, 49), 'RT @mike_pence: Great time stopping by Rock Store BBQ in Marshville for lunch with @jdanbishop, @MarkMeadows & @DavidRouzer! Thanks for the…', None, None, False, 4097, False, 0, 'Twitter for iPhone'], [1171240488072044544, datetime.datetime(2019, 9, 10, 1, 54, 27), 'RT @mike_pence: Thank you to everyone at the @NCGOP working hard to get @jdanbishop to Washington! Keep up the great work! #NC09 https://t.…', None, None, False, 3873, False, 0, 'Twitter for iPhone'], [1171228988024311809, datetime.datetime(2019, 9, 10, 1, 8, 45), 'Beautiful evening in Fayetteville tonight! Big day in North Carolina tomorrow. Make sure you get out and VOTE for D… https://t.co/H2n3BBmtII', None, None, False, 12200, False, 44823, 'Twitter for iPhone'], [1171222442808942593, datetime.datetime(2019, 9, 10, 0, 42, 45), 'THANK YOU Fayetteville, North Carolina! Make sure you get out and VOTE TOMORROW for Dan Bishop in #NC09 and Greg Mu… https://t.co/211MDUPZzL', None, None, False, 14265, False, 50271, 'Twitter for iPhone'], [1171195460670939136, datetime.datetime(2019, 9, 9, 22, 55, 32), 'NORTH CAROLINA — Vote for Dan Bishop in #NC09 and Greg Murphy in #NC03 TOMORROW. Make it a great day for Republicans!', None, None, False, 13347, False, 47263, 'Twitter for iPhone'], [1171193903581675524, datetime.datetime(2019, 9, 9, 22, 49, 21), 'Received an update on Air Force One at MCAS Cherry Point in North Carolina, regarding damage caused by Hurricane Do… https://t.co/nhKoQpIlC7', None, None, False, 6736, False, 30537, 'Twitter for iPhone'], [1171178388460978177, datetime.datetime(2019, 9, 9, 21, 47, 41), 'Departing MCAS Cherry Point in North Carolina for Fayetteville, North Carolina. This is amazing! https://t.co/JDv5HA126A', None, None, False, 11453, False, 46306, 'Twitter for iPhone'], [1171175113883934720, datetime.datetime(2019, 9, 9, 21, 34, 41), 'Speaking to Governor @HenryMcMaster of South Carolina on my way to North Carolina for a big rally for Dan Bishop (… https://t.co/3jJD636ibV', None, None, False, 7407, False, 31097, 'Twitter for iPhone'], [1171153468364451845, datetime.datetime(2019, 9, 9, 20, 8, 40), 'To every one of the HEROES we recognized today — THANK YOU and God Bless You All! https://t.co/JWKwylpdiO', None, None, False, 15767, False, 67595, 'Twitter for iPhone'], [1171148370854862848, datetime.datetime(2019, 9, 9, 19, 48, 25), 'RT @WhiteHouse: President @realDonaldTrump awarded six police officers from Dayton, Ohio, with the Medal of Valor and honored five American…', None, None, False, 9078, False, 0, 'Twitter for iPhone'], [1171120177196544000, datetime.datetime(2019, 9, 9, 17, 56, 23), 'We have been serving as policemen in Afghanistan, and that was not meant to be the job of our Great Soldiers, the f… https://t.co/JlLmK6kldi', None, None, False, 15199, False, 67676, 'Twitter for iPhone'], [1171118516864454657, datetime.datetime(2019, 9, 9, 17, 49, 47), '...the Economy, where there is NO Recession, much to the regret of the LameStream Media! They are working overtime… https://t.co/cwc1Eb4Xs3', 'realDonaldTrump', 1171118507712503813, False, 10871, False, 48779, 'Twitter for iPhone'], [1171118507712503813, datetime.datetime(2019, 9, 9, 17, 49, 45), '...the look of turmoil in the White House, of which there is none. I view much of the media as simply an arm of the… https://t.co/tuL8I308LX', 'realDonaldTrump', 1171118506089361409, False, 10710, False, 48490, 'Twitter for iPhone'], [1171118506089361409, datetime.datetime(2019, 9, 9, 17, 49, 44), 'A lot of Fake News is being reported that I overruled the VP and various advisers on a potential Camp David meeting… https://t.co/tx6PhAiS36', None, None, False, 13785, False, 59495, 'Twitter for iPhone'], [1171103084728279040, datetime.datetime(2019, 9, 9, 16, 48, 28), 'RT @WhiteHouse: Just now, President @realDonaldTrump honored 11 incredible patriots, each of whom stepped forward to save lives in the face…', None, None, False, 9460, False, 0, 'Twitter for iPhone'], [1171074780566622208, datetime.datetime(2019, 9, 9, 14, 55, 59), 'The Trump Administration has achieved more in the first 2 1/2 years of its existence than perhaps any administratio… https://t.co/dB4n9OYKlg', None, None, False, 18257, False, 73512, 'Twitter for iPhone'], [1171058875220541441, datetime.datetime(2019, 9, 9, 13, 52, 47), 'I had nothing to do with the decision of our great @VP Mike Pence to stay overnight at one of the Trump owned resor… https://t.co/5aYxOkQZEz', None, None, False, 12252, False, 60517, 'Twitter for iPhone'], [1171056605233852416, datetime.datetime(2019, 9, 9, 13, 43, 46), 'I know nothing about an Air Force plane landing at an airport (which I do not own and have nothing to do with) near… https://t.co/CIdvPFJSki', None, None, False, 16462, False, 84422, 'Twitter for iPhone'], [1171051473607823360, datetime.datetime(2019, 9, 9, 13, 23, 23), '..that this Administration has done. They don’t talk about the great economy, the big tax and regulation cuts, the… https://t.co/0vkVXkU2Z0', 'realDonaldTrump', 1171051472689270784, False, 9626, False, 42357, 'Twitter for iPhone'], [1171051472689270784, datetime.datetime(2019, 9, 9, 13, 23, 22), 'As bad as @CNN is, Comcast MSNBC is worse. Their ratings are also way down because they have lost all credibility.… https://t.co/mhmgdc5ojY', None, None, False, 13157, False, 57277, 'Twitter for iPhone'], [1171046015106990081, datetime.datetime(2019, 9, 9, 13, 1, 41), '...But most importantly, @CNN is bad for the USA. Their International Division spews bad information & Fake News al… https://t.co/NAj7xHBrtJ', 'realDonaldTrump', 1171046014234648576, False, 12252, False, 49367, 'Twitter for iPhone'], [1171046014234648576, datetime.datetime(2019, 9, 9, 13, 1, 41), 'Great news that an activist investor is now involved with AT&T. As the owner of VERY LOW RATINGS @CNN, perhaps they… https://t.co/Va8V9Tjhsc', None, None, False, 12864, False, 53374, 'Twitter for iPhone'], [1171022839962644480, datetime.datetime(2019, 9, 9, 11, 29, 36), '94% Approval Rating in the Republican Party, a record. Thank you!', None, None, False, 19377, False, 102338, 'Twitter for iPhone'], [1171017507345506305, datetime.datetime(2019, 9, 9, 11, 8, 24), 'House Republicans should allow Chairs of Committees to remain for longer than 6 years. It forces great people, and… https://t.co/iNcXS3XgWz', None, None, False, 8683, False, 38152, 'Twitter for iPhone'], [1171014997339713536, datetime.datetime(2019, 9, 9, 10, 58, 26), '...but then he ran for Congress and won, only to lose his re-elect after I Tweeted my endorsement, on Election Day,… https://t.co/DZwVdC9QL1', 'realDonaldTrump', 1171014995452321792, False, 13138, False, 62853, 'Twitter for iPhone'], [1171014995452321792, datetime.datetime(2019, 9, 9, 10, 58, 25), 'When the former Governor of the Great State of South Carolina, @MarkSanford, was reported missing, only to then say… https://t.co/44yqnYybTo', None, None, False, 14481, False, 62408, 'Twitter for iPhone'], [1171013146078777344, datetime.datetime(2019, 9, 9, 10, 51, 5), 'North Carolina, vote for Dan Bishop tomorrow. We need him badly in Washington! His opponent is a far left Sanctuary Cities supporter.', None, None, False, 16539, False, 56858, 'Twitter for iPhone'], [1171010498009141248, datetime.datetime(2019, 9, 9, 10, 40, 33), 'RT @JuddPDeere45: Today, @POTUS @realDonaldTrump was informed that His Highness Sheikh Sabah Al-Ahmad Al-Jaber Al-Sabah, Amir of the State…', None, None, False, 3742, False, 0, 'Twitter for iPhone'], [1171010489968672768, datetime.datetime(2019, 9, 9, 10, 40, 31), 'RT @JuddPDeere45: .... The @POTUS wishes his friend, the Amir, a speedy recovery and looks forward to welcoming him back to Washington as s…', None, None, False, 3437, False, 0, 'Twitter for iPhone'], [1171010440928944133, datetime.datetime(2019, 9, 9, 10, 40, 20), 'RT @FEMA_Pete: I met with @NCemergency officials today to discuss @fema support as they assess damage and address needs in hard-hit communi…', None, None, False, 3103, False, 0, 'Twitter for iPhone'], [1171006228153155584, datetime.datetime(2019, 9, 9, 10, 23, 35), "RT @MariaBartiromo: Navarro: Trump's economy is solid as a rock https://t.co/6az9d2ixWq  @SundayFutures @FoxNews", None, None, False, 5935, False, 0, 'Twitter for iPhone'], [1171005603944259584, datetime.datetime(2019, 9, 9, 10, 21, 6), 'Maria & John understood the dishonesty & deception from the very beginning! https://t.co/kyYx4S56Z0', None, None, False, 10205, False, 34396, 'Twitter for iPhone'], [1170897587387412480, datetime.datetime(2019, 9, 9, 3, 11, 53), '.....the importance or passage of Criminal Justice Reform. They only talk about the minor players, or people that h… https://t.co/V6D76ezyY6', 'realDonaldTrump', 1170897586364006405, False, 13127, False, 61657, 'Twitter for iPhone'], [1170897586364006405, datetime.datetime(2019, 9, 9, 3, 11, 53), '....musician @johnlegend, and his filthy mouthed wife, are talking now about how great it is - but I didn’t see the… https://t.co/7H3Sqbciq4', 'realDonaldTrump', 1170897585336475648, False, 15523, False, 69401, 'Twitter for iPhone'], [1170897585336475648, datetime.datetime(2019, 9, 9, 3, 11, 53), '....A man named @VanJones68, and many others, were profusely grateful (at that time!). I SIGNED IT INTO LAW, no one… https://t.co/UtKHqrOsZs', 'realDonaldTrump', 1170897584510124032, False, 6975, False, 27730, 'Twitter for iPhone'], [1170897584510124032, datetime.datetime(2019, 9, 9, 3, 11, 53), 'When all of the people pushing so hard for Criminal Justice Reform were  unable to come even close to getting it do… https://t.co/OO3rDGNW84', None, None, False, 18793, False, 83653, 'Twitter for iPhone'], [1170887296616472577, datetime.datetime(2019, 9, 9, 2, 31), 'RT @WhiteHouse: “This is a momentous occasion for the arts." @FLOTUS, who is the Honorary Chair of the John F. Kennedy Center for the Perfo…', None, None, False, 8211, False, 0, 'Twitter for iPhone'], [1170887178446131200, datetime.datetime(2019, 9, 9, 2, 30, 32), 'RT @IvankaTrump: I look forward to visiting Alabama on Tuesday! 🇺🇸 https://t.co/RlHTCOv4JK', None, None, False, 6667, False, 0, 'Twitter for iPhone'], [1170883932914667520, datetime.datetime(2019, 9, 9, 2, 17, 38), 'https://t.co/NeTvaaeVTR', None, None, False, 12427, False, 50078, 'Twitter for iPhone'], [1170789259068022785, datetime.datetime(2019, 9, 8, 20, 1, 26), 'RT @arielmou: \u2066#Video of @IvankaTrump\u2069 dancing with Paraguayan women, as her South American trip comes to an end today. #WGDP https://t.co/…', None, None, False, 7156, False, 0, 'Twitter for iPhone'], [1170789032625938433, datetime.datetime(2019, 9, 8, 20, 0, 32), 'RT @VP: Thank you @IvankaTrump for continuing to show America’s support for the people of Venezuela! We will not stop fighting until they h…', None, None, False, 8313, False, 0, 'Twitter for iPhone'], [1170788927164309504, datetime.datetime(2019, 9, 8, 20, 0, 7), 'RT @thehill: YESTERDAY: Ivanka Trump meets with the Paraguay Pres. Mario Abdo Benítez during her trip in South America. https://t.co/rAaLK9…', None, None, False, 4456, False, 0, 'Twitter for iPhone'], [1170788493603352578, datetime.datetime(2019, 9, 8, 19, 58, 23), 'RT @JessicaDitto45: “We stand with the people of Venezuela in their struggle to restore democracy, freedom and rule of law. It was deeply m…', None, None, False, 5712, False, 0, 'Twitter for iPhone'], [1170786968889909249, datetime.datetime(2019, 9, 8, 19, 52, 20), 'Congratulations to @JudgeJeanine Pirro on having, again, the Number One Best Selling Book!', None, None, False, 13577, False, 71014, 'Twitter for iPhone'], [1170782374843564034, datetime.datetime(2019, 9, 8, 19, 34, 4), 'Looking forward to being in the North Carolina tomorrow night. We’re having a BIG RALLY for a great guy, Dan Bishop… https://t.co/dnEpFwdDrL', None, None, False, 17324, False, 68985, 'Twitter for iPhone'], [1170742727333568514, datetime.datetime(2019, 9, 8, 16, 56, 32), 'WE ARE BUILDING THE WALL... https://t.co/OQQaag2ZUW', None, None, False, 25077, False, 108166, 'Twitter for iPhone'], [1170548948135796736, datetime.datetime(2019, 9, 8, 4, 6, 31), 'Leakin’ Lyin’ James Comey! https://t.co/0qr5BcbRcl', None, None, False, 17769, False, 59292, 'Twitter for iPhone'], [1170546650651271169, datetime.datetime(2019, 9, 8, 3, 57, 23), 'https://t.co/QeUbwdsWfr', None, None, False, 46451, False, 169761, 'Twitter for iPhone'], [1170469621348098049, datetime.datetime(2019, 9, 7, 22, 51, 18), '....only made it worse! If they cannot agree to a ceasefire during these very important peace talks, and would even… https://t.co/M3BctNpVqu', 'realDonaldTrump', 1170469619154530305, False, 19146, False, 85760, 'Twitter for iPhone'], [1170469619154530305, datetime.datetime(2019, 9, 7, 22, 51, 18), '....an attack in Kabul that killed one of our great great soldiers, and 11 other people. I immediately cancelled th… https://t.co/y8kye41ORQ', 'realDonaldTrump', 1170469618177236992, False, 17487, False, 73903, 'Twitter for iPhone'], [1170469618177236992, datetime.datetime(2019, 9, 7, 22, 51, 17), 'Unbeknownst to almost everyone, the major Taliban leaders and, separately, the President of Afghanistan, were going… https://t.co/1HtmeRqqzE', None, None, False, 22670, False, 85463, 'Twitter for iPhone'], [1170452431165100037, datetime.datetime(2019, 9, 7, 21, 43), 'RT @PoliticalShort: “News coverage of President Trump has been 92% negative. The most egregious and dangerous forms of this bias thrived th…', None, None, False, 11160, False, 0, 'Twitter for iPhone'], [1170452168840757254, datetime.datetime(2019, 9, 7, 21, 41, 57), 'RT @BreitbartNews: Elizabeth Warren promises to declare war on American energy. \n"I will ban fracking—everywhere." https://t.co/YEenw2MUfV', None, None, False, 7692, False, 0, 'Twitter for iPhone'], [1170452150272626688, datetime.datetime(2019, 9, 7, 21, 41, 53), 'RT @BreitbartNews: Swedish behavioral scientist Magnus Söderlund has suggested that eating other people after they die could be a means of…', None, None, False, 7264, False, 0, 'Twitter for iPhone'], [1170451433507962880, datetime.datetime(2019, 9, 7, 21, 39, 2), 'RT @JudicialWatch: .@realDonaldTrump retweeted our petition! Right now, our borders are being used as gateways for drug cartels & violent c…', None, None, False, 8287, False, 0, 'Twitter for iPhone'], [1170447254215450624, datetime.datetime(2019, 9, 7, 21, 22, 25), 'RT @BreitbartNews: Everything is on the line. "...the Democrats will move for an outright repeal of the Second Amendment," said @RepMoBrook…', None, None, False, 7540, False, 0, 'Twitter for iPhone'], [1170438527533944832, datetime.datetime(2019, 9, 7, 20, 47, 45), 'RT @realDonaldTrump: https://t.co/J3aTzBG7ao', None, None, False, 51702, False, 0, 'Twitter for iPhone'], [1170437809796255745, datetime.datetime(2019, 9, 7, 20, 44, 54), '...FAKE NEWS. I would like very much to stop referring to this ridiculous story, but the LameStream Media just won’… https://t.co/xPbrXAWleG', 'realDonaldTrump', 1170437808894427140, False, 13972, False, 65167, 'Twitter for iPhone'], [1170437808894427140, datetime.datetime(2019, 9, 7, 20, 44, 53), 'The Failing New York Times stated, in an article written by Obama flunky Peter Baker (who lovingly wrote Obama book… https://t.co/Ngg3WUh5Yc', None, None, False, 14462, False, 69024, 'Twitter for iPhone'], [1170426165393334274, datetime.datetime(2019, 9, 7, 19, 58, 37), 'Our Economy is doing great!!!!! https://t.co/JnnEbyWQek', None, None, False, 12422, False, 52746, 'Twitter for iPhone'], [1170425468744622082, datetime.datetime(2019, 9, 7, 19, 55, 51), 'RT @VP: The United States stands without apology for a strong, prosperous, and free United Kingdom and we fully support their decision to l…', None, None, False, 18557, False, 0, 'Twitter for iPhone'], [1170425232861085696, datetime.datetime(2019, 9, 7, 19, 54, 55), 'RT @WhiteHouseCEA: New from @BLS_gov - in August, the #unemployment rate remained at 3.7%, and has been under 4% for 18 consecutive months,…', None, None, False, 5230, False, 0, 'Twitter for iPhone'], [1170425159343386625, datetime.datetime(2019, 9, 7, 19, 54, 38), 'RT @WhiteHouse: Congress has an opportunity to replace NAFTA with a deal that protects American workers—and "would boost the fortunes of Am…', None, None, False, 7070, False, 0, 'Twitter for iPhone'], [1170422093500026880, datetime.datetime(2019, 9, 7, 19, 42, 27), 'JOBS, JOBS, JOBS! https://t.co/NeTvaaeVTR', None, None, False, 15115, False, 64434, 'Twitter for iPhone'], [1170353869949407232, datetime.datetime(2019, 9, 7, 15, 11, 21), 'Congratulations to the GREAT Jerry West! https://t.co/BD6FUD6JwP https://t.co/tNMJCRD4ft', None, None, False, 8872, False, 42731, 'Twitter for iPhone'], [1170333738443710465, datetime.datetime(2019, 9, 7, 13, 51, 21), 'Thank you Katie. The U.S. is doing great! https://t.co/FT2ERbVPf6', None, None, False, 12797, False, 53563, 'Twitter for iPhone'], [1170333046672936965, datetime.datetime(2019, 9, 7, 13, 48, 36), 'Russia and Ukraine just swapped large numbers of prisoners. Very good news, perhaps a first giant step to peace. Co… https://t.co/8BeC7aXSAG', None, None, False, 15339, False, 75177, 'Twitter for iPhone'], [1170324532562931713, datetime.datetime(2019, 9, 7, 13, 14, 46), '“In 22 years of patrolling our Southern Border, I have never seen Mexico act like a true Border Security Partner un… https://t.co/Avu0Oo5FkO', None, None, False, 21243, False, 85803, 'Twitter for iPhone'], [1170292743865810944, datetime.datetime(2019, 9, 7, 11, 8, 27), 'The Washington Post’s @PhilipRucker (Mr. Off the Record) & @AshleyRParker, two nasty lightweight reporters, shouldn… https://t.co/1jxEbYZ3By', None, None, False, 9993, False, 37919, 'Twitter for iPhone'], [1170288754520657920, datetime.datetime(2019, 9, 7, 10, 52, 36), 'I want to congratulate @senatemajldr Mitch McConnell and all Republicans. Today I signed the 160th Federal Judge to… https://t.co/geWQOLjWS1', None, None, False, 18589, False, 74459, 'Twitter for iPhone'], [1170285514324414464, datetime.datetime(2019, 9, 7, 10, 39, 44), '....I would also like to thank “Papa” Doug Manchester, hopefully the next Ambassador to the Bahamas, for the incred… https://t.co/OVx6JaL5hS', 'realDonaldTrump', 1170285513376485378, False, 10990, False, 59749, 'Twitter for iPhone'], [1170285513376485378, datetime.datetime(2019, 9, 7, 10, 39, 43), 'Thank you to Bahamian Prime Minister Hubert Minnis for your very gracious and kind words in saying that without the… https://t.co/6u5m5MlfDe', None, None, False, 16812, False, 87794, 'Twitter for iPhone'], [1170171081853931520, datetime.datetime(2019, 9, 7, 3, 5, 1), 'China just enacted a major stimulus plan. With all the Tariffs THEY are paying to the USA, Billions and Billions of… https://t.co/8dTLSHkL6L', None, None, False, 16316, False, 65788, 'Twitter for iPhone'], [1170166239483826176, datetime.datetime(2019, 9, 7, 2, 45, 46), 'PROMISES MADE, PROMISES KEPT! https://t.co/chGpYgkmo7', None, None, False, 15767, False, 58479, 'Twitter for iPhone'], [1170131655434129408, datetime.datetime(2019, 9, 7, 0, 28, 21), 'https://t.co/sQ70fKcTjV', None, None, False, 13457, False, 52895, 'Twitter for iPhone'], [1170123710164013056, datetime.datetime(2019, 9, 6, 23, 56, 47), '....that were not hit – and that are in good condition. Any cruise ship companies willing to act as stationary hous… https://t.co/WfqgSl2idm', 'realDonaldTrump', 1170123708696072192, False, 9975, False, 49422, 'Twitter for iPhone'], [1170123708696072192, datetime.datetime(2019, 9, 6, 23, 56, 46), 'The @USCG, @FEMA, and all others, along with other countries that have been helping, have been asked to move people… https://t.co/oyLyn3feGU', None, None, False, 10390, False, 51512, 'Twitter for iPhone'], [1170097018901020673, datetime.datetime(2019, 9, 6, 22, 10, 43), '“The Washington Post’s Lost Summer” https://t.co/jHkZyiJwZL', None, None, False, 8846, False, 31210, 'Twitter for iPhone'], [1170096093348139009, datetime.datetime(2019, 9, 6, 22, 7, 2), 'https://t.co/tsIMIawIxh', None, None, False, 15418, False, 45217, 'Twitter for iPhone'], [1170089069105340416, datetime.datetime(2019, 9, 6, 21, 39, 7), 'https://t.co/J3aTzBG7ao', None, None, False, 51702, False, 173362, 'Twitter for iPhone'], [1169992234382610432, datetime.datetime(2019, 9, 6, 15, 14, 20), '“China is eating the Tariffs.” Billions pouring into USA. Targeted Patriot Farmers getting massive Dollars from the… https://t.co/2vDquqQM2C', None, None, False, 18319, False, 76338, 'Twitter for iPhone'], [1169983251160731651, datetime.datetime(2019, 9, 6, 14, 38, 38), 'The Economy is great. The only thing adding to “uncertainty” is the Fake News!', None, None, False, 15984, False, 67894, 'Twitter for iPhone'], [1169982535646031873, datetime.datetime(2019, 9, 6, 14, 35, 48), 'Great job by FEMA, Law Enforcement, First Responders, U.S. Coast Guard, and ALL! Keep going, we all appreciate what you are doing!', None, None, False, 11013, False, 51850, 'Twitter for iPhone'], [1169981020634013696, datetime.datetime(2019, 9, 6, 14, 29, 47), '....partner should start playing it straight. It would be so much better for our Country!', 'realDonaldTrump', 1169981019228913664, False, 9245, False, 46304, 'Twitter for iPhone'], [1169981019228913664, datetime.datetime(2019, 9, 6, 14, 29, 46), '....This nonsense has never happened to another President. Four days of corrupt reporting, still without an apology… https://t.co/XtV0pk3cIg', 'realDonaldTrump', 1169981017794535432, False, 10528, False, 49913, 'Twitter for iPhone'], [1169981017794535432, datetime.datetime(2019, 9, 6, 14, 29, 46), 'The Fake News Media was fixated on the fact that I properly said, at the beginnings of Hurricane Dorian, that in ad… https://t.co/xbmq9l9POT', None, None, False, 12647, False, 59726, 'Twitter for iPhone'], [1169967054755172354, datetime.datetime(2019, 9, 6, 13, 34, 17), 'Larry Kudlow on @Varneyco now!', None, None, False, 4809, False, 26120, 'Twitter for iPhone'], [1169960993922981889, datetime.datetime(2019, 9, 6, 13, 10, 12), 'Our great @JudgeJeanine has just written a book that will add to the tremendous success of her last number one best… https://t.co/dWv2HrwZ8V', None, None, False, 10244, False, 41970, 'Twitter for iPhone'], [1169956429366779904, datetime.datetime(2019, 9, 6, 12, 52, 4), 'Great interview of Sarah Sanders by @foxandfriends. She is a terrific person with a great future!', None, None, False, 9106, False, 47356, 'Twitter for iPhone'], [1169953150251556864, datetime.datetime(2019, 9, 6, 12, 39, 2), 'Congratulations to @edhenry and his sister on a great success. What a wonderful thing to do!', None, None, False, 7802, False, 42392, 'Twitter for iPhone'], [1169948967947395072, datetime.datetime(2019, 9, 6, 12, 22, 25), 'I agree with @jimcramer, the Fed should lower rates. They were WAY too early to raise, and Way too late to cut - an… https://t.co/8Q5SSfxtt1', None, None, False, 10307, False, 42223, 'Twitter for iPhone'], [1169948497241677824, datetime.datetime(2019, 9, 6, 12, 20, 32), 'DACA will be going before the Supreme Court. It is a document that even President Obama didn’t feel he had the lega… https://t.co/ikon4DYlkQ', None, None, False, 14482, False, 60481, 'Twitter for iPhone'], [1169945441233985536, datetime.datetime(2019, 9, 6, 12, 8, 24), '....President Obama never had the legal right to sign DACA, and he indicated so at the time of signing. But In any… https://t.co/2clDkXY7Lu', 'realDonaldTrump', 1169945440240001025, False, 12980, False, 53056, 'Twitter for iPhone'], [1169945440240001025, datetime.datetime(2019, 9, 6, 12, 8, 24), '....have the discretion to end the program that President Obama began in his discretion. That program was unlawful… https://t.co/fLKkQ6EQDP', 'realDonaldTrump', 1169945439434674176, False, 10961, False, 47905, 'Twitter for iPhone'], [1169945439434674176, datetime.datetime(2019, 9, 6, 12, 8, 23), 'The Immigration Law Institute’s Christopher Hajec says, “The Supreme Court has to look st whether DACA is lawful. W… https://t.co/LfWAx8f2mM', None, None, False, 12751, False, 54444, 'Twitter for iPhone'], [1169841045359607809, datetime.datetime(2019, 9, 6, 5, 13, 34), "RT @NHC_Atlantic: Here's the 1am EDT update on #Dorian: Tropical Storm Conditions Continue to Spread Northward Along the North Carolina Coa…", None, None, False, 2729, False, 0, 'Twitter for iPhone'], [1169841035322638337, datetime.datetime(2019, 9, 6, 5, 13, 32), 'RT @NHC_Atlantic: Hurricane #Dorian Advisory 51: Core of Hurricane Dorian Brushing the Coast of North Carolina. https://t.co/VqHn0u1vgc', None, None, False, 2491, False, 0, 'Twitter for iPhone'], [1169815875966210049, datetime.datetime(2019, 9, 6, 3, 33, 33), '....that our economy is very strong. If the Fed would lower rates to where the bond market says they should be, the… https://t.co/KqEzK4T3fe', 'realDonaldTrump', 1169815874988986369, False, 10698, False, 50936, 'Twitter for iPhone'], [1169815874988986369, datetime.datetime(2019, 9, 6, 3, 33, 33), '“I think President Trump is set in his ways because he doesn’t see any weakening. I mean, look at the joblessness r… https://t.co/AUINvObAbz', None, None, False, 12740, False, 62257, 'Twitter for iPhone'], [1169814696129523712, datetime.datetime(2019, 9, 6, 3, 28, 52), 'RT @MadMoneyOnCNBC: .@JimCramer: Thursday’s positive economic data may get some commentators to ease up on the desire to endlessly call for…', None, None, False, 5797, False, 0, 'Twitter for iPhone'], [1169782689257447424, datetime.datetime(2019, 9, 6, 1, 21, 41), 'Looking forward to watching @SarahHuckabee Sanders tomorrow morning on @FoxandFriends, by far the #1 rated show on… https://t.co/GqCfzCMUr3', None, None, False, 13027, False, 64438, 'Twitter for iPhone'], [1169759456277729282, datetime.datetime(2019, 9, 5, 23, 49, 22), 'Great job done by @GovRonDesantis, @SenRickScott, Senator @MarcoRubio, and all of the those from Florida that were… https://t.co/SU7VdL8Wlb', None, None, False, 9157, False, 41392, 'Twitter for iPhone'], [1169758141795459080, datetime.datetime(2019, 9, 5, 23, 44, 8), 'Just got off the phone with Governor Brian Kemp (@GovKemp) of Georgia. Happy to hear that things are looking good f… https://t.co/sCEuO9zYLk', None, None, False, 9635, False, 49508, 'Twitter for iPhone'], [1169756027035803650, datetime.datetime(2019, 9, 5, 23, 35, 44), 'Just spoke to Governor @HenryMcMaster of South Carolina regarding Hurricane Dorian. I informed Henry that we are mo… https://t.co/goMiwa26h5', None, None, False, 8441, False, 42511, 'Twitter for iPhone'], [1169753952130359297, datetime.datetime(2019, 9, 5, 23, 27, 29), 'Just talked to Governor Roy Cooper of North Carolina as Hurricane Dorian ominously comes up the East Coast. We are… https://t.co/6iylYTyC5x', None, None, False, 8412, False, 40820, 'Twitter for iPhone'], [1169719333490167808, datetime.datetime(2019, 9, 5, 21, 9, 56), 'RT @NHC_Atlantic: Here are the 5pm EDT Key Messages on Hurricane #Dorian. Life-threatening storm surge and dangerous winds and flash floodi…', None, None, False, 3403, False, 0, 'Twitter for iPhone'], [1169706294242136073, datetime.datetime(2019, 9, 5, 20, 18, 7), 'I was with you all the way Alabama. The Fake News Media was not! https://t.co/gO5pwahaj9', None, None, False, 14651, False, 58054, 'Twitter for iPhone'], [1169705282123046913, datetime.datetime(2019, 9, 5, 20, 14, 5), 'Just as I said, Alabama was originally projected to be hit. The Fake News denies it! https://t.co/elJ7ROfm2p', None, None, False, 11909, False, 48916, 'Twitter for iPhone'], [1169668612749217792, datetime.datetime(2019, 9, 5, 17, 48, 23), "RT @NWSColumbia: [Sep 5, 1`:25 PM] - Winds are picking back up @NOAABuoyData #41004, 47 miles SE from Charleston as #Dorian's eye moves awa…", None, None, False, 2792, False, 0, 'Twitter for iPhone'], [1169668549213851650, datetime.datetime(2019, 9, 5, 17, 48, 8), 'RT @NHC_Atlantic: Here are the 11 am EDT key messages on Hurricane #Dorian.  The latest full advisory is always available at https://t.co/t…', None, None, False, 2647, False, 0, 'Twitter for iPhone'], [1169637650627747845, datetime.datetime(2019, 9, 5, 15, 45, 21), '....His dedication to Israel and to seeking peace between Israel and the Palestinians won’t be forgotten. He will b… https://t.co/HMnwu7Zvpa', 'realDonaldTrump', 1169637649151406081, False, 7964, False, 48576, 'Twitter for iPhone'], [1169637649151406081, datetime.datetime(2019, 9, 5, 15, 45, 21), 'After almost 3 years in my Administration, Jason Greenblatt will be leaving to pursue work in the private sector. J… https://t.co/cPYYVCQdqp', None, None, False, 9839, False, 59132, 'Twitter for iPhone'], [1169606328945451009, datetime.datetime(2019, 9, 5, 13, 40, 53), 'Really Good Jobs Numbers!', None, None, False, 13225, False, 69537, 'Twitter for iPhone'], [1169606058148605953, datetime.datetime(2019, 9, 5, 13, 39, 49), 'Alabama was going to be hit or grazed, and then Hurricane Dorian took a different path (up along the East Coast). T… https://t.co/p7jFHFVuLI', None, None, False, 10739, False, 49142, 'Twitter for iPhone'], [1169600039188160512, datetime.datetime(2019, 9, 5, 13, 15, 54), '....said what she did, even being on a much higher rated show, she would have been thrown off television. Will Fake… https://t.co/G0lOTqvxYA', 'realDonaldTrump', 1169600037053247488, False, 20306, False, 82939, 'Twitter for iPhone'], [1169600037053247488, datetime.datetime(2019, 9, 5, 13, 15, 53), 'Bad “actress” Debra The Mess Messing is in hot water. She wants to create a “Blacklist” of Trump supporters, & is b… https://t.co/HqLMYkM1hA', None, None, False, 25974, False, 101074, 'Twitter for iPhone'], [1169584600055799810, datetime.datetime(2019, 9, 5, 12, 14, 33), "RT @NHC_Atlantic: Beyond Hurricane #Dorian and TS #Gabrielle, we're monitoring 3 other disturbances with a low chance of becoming tropical…", None, None, False, 4042, False, 0, 'Twitter for iPhone'], [1169584505797189632, datetime.datetime(2019, 9, 5, 12, 14, 10), 'RT @NWSWilmingtonNC: Video of a tornado passing near Pender County Fire Station 18 along Highway 17 near Sidbury Rd. Video courtesty of Sta…', None, None, False, 4899, False, 0, 'Twitter for iPhone'], [1169584437899747330, datetime.datetime(2019, 9, 5, 12, 13, 54), 'RT @NHC_Atlantic: 7 AM EDT Tropical Cyclone Update for Hurricane #Dorian: Tropical Storm Conditions Occurring Along Portions of the South C…', None, None, False, 2374, False, 0, 'Twitter for iPhone'], [1169582555697426432, datetime.datetime(2019, 9, 5, 12, 6, 25), 'RT @DaveNYviii: President Trump Border Update \n500 Miles of Wall Complete by Close of 2020\nIrregular Migration Reduced by 50%\n\n#BuildTheWal…', None, None, False, 7714, False, 0, 'Twitter for iPhone'], [1169578377352765440, datetime.datetime(2019, 9, 5, 11, 49, 49), 'RT @realDonaldTrump: This was the originally projected path of the Hurricane in its early stages. As you can see, almost all models predict…', None, None, False, 14155, False, 0, 'Twitter for iPhone'], [1169578155948072962, datetime.datetime(2019, 9, 5, 11, 48, 56), '....Instead it turned North and went up the coast, where it continues now. In the one model through Florida, the Gr… https://t.co/OvkyDRpGEr', 'realDonaldTrump', 1169578155096584192, False, 9805, False, 54707, 'Twitter for iPhone'], [1169578155096584192, datetime.datetime(2019, 9, 5, 11, 48, 56), 'In the early days of the hurricane, when it was predicted that Dorian would go through Miami or West Palm Beach, ev… https://t.co/R7dZtTB7hH', None, None, False, 10203, False, 56035, 'Twitter for iPhone'], [1169571407816253441, datetime.datetime(2019, 9, 5, 11, 22, 7), "RT @militarykind: The announcer couldn't even get through his speech without choking up for this sweet Army mom homecoming.❤️⚾️🇺🇸 https://t…", None, None, False, 6002, False, 0, 'Twitter for iPhone'], [1169459039132102657, datetime.datetime(2019, 9, 5, 3, 55, 37), 'Thank you Rad - looking great! https://t.co/YeKXSNjKwW', None, None, False, 12010, False, 44545, 'Twitter for iPhone'], [1169455923712221185, datetime.datetime(2019, 9, 5, 3, 43, 14), 'Thank you Terrence. Best Employment Numbers In History for African Americans! https://t.co/YCf2WT4XHt', None, None, False, 23093, False, 82299, 'Twitter for iPhone'], [1169447181872521218, datetime.datetime(2019, 9, 5, 3, 8, 30), 'RT @NHC_Atlantic: 7 pm Tropical Cyclone Update:  #Dorian lashing the Georgia and South Carolina Coast. The next intermediate advisory will…', None, None, False, 2504, False, 0, 'Twitter for iPhone'], [1169415182029901824, datetime.datetime(2019, 9, 5, 1, 1, 20), 'https://t.co/bxSiT2zQDj', None, None, False, 11366, False, 35061, 'Twitter for iPhone'], [1169412199611326464, datetime.datetime(2019, 9, 5, 0, 49, 29), '....information does come out.” Charlie Hurt, Washington Times  @LouDobbs', 'realDonaldTrump', 1169412198692732928, False, 12724, False, 55150, 'Twitter for iPhone'], [1169412198692732928, datetime.datetime(2019, 9, 5, 0, 49, 29), '....facts, and that should terrify every American regardless of their political stripe. The idea that all of that i… https://t.co/QyrnqQe00Q', 'realDonaldTrump', 1169412197841350657, False, 13804, False, 58929, 'Twitter for iPhone'], [1169412197841350657, datetime.datetime(2019, 9, 5, 0, 49, 29), '“Absolutely nothing is more important than going back & getting to the bottom of the origins of the investigation.… https://t.co/yzx0Ah2YtS', None, None, False, 22271, False, 85191, 'Twitter for iPhone'], [1169375550806351872, datetime.datetime(2019, 9, 4, 22, 23, 51), 'This was the originally projected path of the Hurricane in its early stages. As you can see, almost all models pred… https://t.co/BogxK40zE1', None, None, False, 14155, False, 59761, 'Twitter for iPhone'], [1169366511439552512, datetime.datetime(2019, 9, 4, 21, 47, 56), 'State Rep Greg Murphy is running for Congress in North Carolina, District 3. We really need Greg in Washington. He… https://t.co/Jl0otOAO0f', None, None, False, 13690, False, 49343, 'Twitter for iPhone'], [1169360837498351618, datetime.datetime(2019, 9, 4, 21, 25, 23), 'RT @realDonaldTrump: The Great State of North Carolina has EARLY VOTING for a very important Congressional (Ninth) race. Please vote early…', None, None, False, 21823, False, 0, 'Twitter for iPhone'], [1169356705857187840, datetime.datetime(2019, 9, 4, 21, 8, 58), '7. The badly flawed Paris Climate Agreement protects the polluters, hurts Americans, and cost a fortune. NOT ON MY… https://t.co/DSsydY8pRt', 'realDonaldTrump', 1169356704926109696, False, 12309, False, 51380, 'Twitter for iPhone'], [1169356704926109696, datetime.datetime(2019, 9, 4, 21, 8, 58), "6. The Democrats’ destructive “environmental” proposals will raise your energy bill and prices at the pump. \n\nDon't… https://t.co/oXXjsH7prF", 'realDonaldTrump', 1169356704028516353, False, 10898, False, 47035, 'Twitter for iPhone'], [1169356704028516353, datetime.datetime(2019, 9, 4, 21, 8, 58), "4. The U.S. now leads the world in energy production...\n\nBUT...\n \n5. Who's got the world's cleanest and safest air and water? \n\nAMERICA!", 'realDonaldTrump', 1169356703126773762, False, 8336, False, 28738, 'Twitter for iPhone'], [1169356703126773762, datetime.datetime(2019, 9, 4, 21, 8, 58), '1. Which country has the largest carbon emission reduction?\n\nAMERICA!\n\n2. Who has dumped the most carbon into the a… https://t.co/eUm8MaaqmW', 'realDonaldTrump', 1169356701943894017, False, 11142, False, 33353, 'Twitter for iPhone'], [1169356701943894017, datetime.datetime(2019, 9, 4, 21, 8, 57), '8 FACTS that #FakeNewsCNN will ignore in tonight’s “Climate Forum”', None, None, False, 15130, False, 57301, 'Twitter for iPhone'], [1169301734725967872, datetime.datetime(2019, 9, 4, 17, 30, 32), 'RT @WhiteHouse: President @realDonaldTrump gives an update on Hurricane #Dorian: https://t.co/CmxAXHY5AO', None, None, False, 7259, False, 0, 'Twitter for iPhone'], [1169291720837816321, datetime.datetime(2019, 9, 4, 16, 50, 45), 'RT @NHC_Atlantic: The Hurricane Warning has been extended northward to the North Carolina/Virginia border, including Albemarle and Pamlico…', None, None, False, 3583, False, 0, 'Twitter for iPhone'], [1169253301138919424, datetime.datetime(2019, 9, 4, 14, 18, 5), '....We can’t have a system where we run our entire economy for the benefit of other countries, which have long char… https://t.co/eUfR2IqrwA', 'realDonaldTrump', 1169253299981303810, False, 12747, False, 57430, 'Twitter for iPhone'], [1169253299981303810, datetime.datetime(2019, 9, 4, 14, 18, 5), '....Trump is doing to China is not lost on the rest of the world. Europe has had among the most protectionist polic… https://t.co/Sec9NUE0u4', 'realDonaldTrump', 1169253298169438208, False, 11690, False, 54739, 'Twitter for iPhone'], [1169253298169438208, datetime.datetime(2019, 9, 4, 14, 18, 4), '“The Chinese are very adept at not accepting anything. You’ve got to be very tough, and that’s what Trump is doing.… https://t.co/KEJUHHOhoN', None, None, False, 17189, False, 78345, 'Twitter for iPhone'], [1169249070990462978, datetime.datetime(2019, 9, 4, 14, 1, 16), 'RT @NHC_Atlantic: @NOAA @NWS Water levels could begin to rise well in advance of the arrival of strong winds.  The surge will be accompanie…', None, None, False, 2734, False, 0, 'Twitter for iPhone'], [1169249032197345281, datetime.datetime(2019, 9, 4, 14, 1, 7), "RT @NHC_Atlantic: Here's the latest #Dorian storm surge forecast from this morning.  The water could reach the following heights above grou…", None, None, False, 3471, False, 0, 'Twitter for iPhone'], [1169248935447281665, datetime.datetime(2019, 9, 4, 14, 0, 44), 'RT @NHC_Atlantic: The @NWSWPC has issued a High Risk area for flash flooding over eastern South Carolina & SE North Carolina for Thursday d…', None, None, False, 2714, False, 0, 'Twitter for iPhone'], [1169246982508072960, datetime.datetime(2019, 9, 4, 13, 52, 58), '“U.S. Winning Trade War With China In Dollars.” CNBC', None, None, False, 13344, False, 60665, 'Twitter for iPhone'], [1169062380040523776, datetime.datetime(2019, 9, 4, 1, 39, 26), '.....on the President of the United States.” @charliekirk11 @trish_regan', 'realDonaldTrump', 1169062379134574592, False, 13449, False, 61978, 'Twitter for iPhone'], [1169062379134574592, datetime.datetime(2019, 9, 4, 1, 39, 25), '“To declassify is so important because if this were a Democrat President or a Democrat Candidate, that was spied on… https://t.co/XVjMZjOtcT', None, None, False, 24728, False, 96036, 'Twitter for iPhone'], [1169053562904678405, datetime.datetime(2019, 9, 4, 1, 4, 24), '“I am so tired of hearing the rationalization of the Left in the country because they hate Donald Trump. Inexplicab… https://t.co/k3eERVIoKk', None, None, False, 28333, False, 118157, 'Twitter for iPhone'], [1169050760098791431, datetime.datetime(2019, 9, 4, 0, 53, 15), 'The truth is that we have a nation that is disgusted with the FBI. We have a crisis of confidence in the number one… https://t.co/zvA0mfegRP', None, None, False, 19518, False, 74157, 'Twitter for iPhone'], [1169048221026590725, datetime.datetime(2019, 9, 4, 0, 43, 10), 'At the request of Senator Thom Tillis, I am getting the North Carolina Emergency Declaration completed and signed t… https://t.co/n0tLM8GrLd', None, None, False, 12388, False, 63332, 'Twitter for iPhone']]
                      id          created_at  \
0    1171760702564052993 2019-09-11 12:21:36   
1    1171760235935125508 2019-09-11 12:19:45   
2    1171758532280143873 2019-09-11 12:12:58   
3    1171758531449643008 2019-09-11 12:12:58   
4    1171743257589690370 2019-09-11 11:12:17   
5    1171742213027586049 2019-09-11 11:08:08   
6    1171741981703311360 2019-09-11 11:07:13   
7    1171738781025746945 2019-09-11 10:54:29   
8    1171736398212272128 2019-09-11 10:45:01   
9    1171735692428419072 2019-09-11 10:42:13   
10   1171735691769929728 2019-09-11 10:42:13   
11   1171733174101131264 2019-09-11 10:32:13   
12   1171728799408500737 2019-09-11 10:14:50   
13   1171651786622537728 2019-09-11 05:08:48   
14   1171642393583656961 2019-09-11 04:31:29   
15   1171631144414208000 2019-09-11 03:46:47   
16   1171629221552283648 2019-09-11 03:39:08   
17   1171622285507289088 2019-09-11 03:11:35   
18   1171614032782123008 2019-09-11 02:38:47   
19   1171613145523195904 2019-09-11 02:35:16   
20   1171611976100917248 2019-09-11 02:30:37   
21   1171595113673347072 2019-09-11 01:23:36   
22   1171590284544827392 2019-09-11 01:04:25   
23   1171586554281615360 2019-09-11 00:49:36   
24   1171586230628311045 2019-09-11 00:48:19   
25   1171547046295171072 2019-09-10 22:12:36   
26   1171475308416884739 2019-09-10 17:27:33   
27   1171475286170292224 2019-09-10 17:27:27   
28   1171475240322383873 2019-09-10 17:27:16   
29   1171452881729228802 2019-09-10 15:58:26   
..                   ...                 ...   
170  1169571407816253441 2019-09-05 11:22:07   
171  1169459039132102657 2019-09-05 03:55:37   
172  1169455923712221185 2019-09-05 03:43:14   
173  1169447181872521218 2019-09-05 03:08:30   
174  1169415182029901824 2019-09-05 01:01:20   
175  1169412199611326464 2019-09-05 00:49:29   
176  1169412198692732928 2019-09-05 00:49:29   
177  1169412197841350657 2019-09-05 00:49:29   
178  1169375550806351872 2019-09-04 22:23:51   
179  1169366511439552512 2019-09-04 21:47:56   
180  1169360837498351618 2019-09-04 21:25:23   
181  1169356705857187840 2019-09-04 21:08:58   
182  1169356704926109696 2019-09-04 21:08:58   
183  1169356704028516353 2019-09-04 21:08:58   
184  1169356703126773762 2019-09-04 21:08:58   
185  1169356701943894017 2019-09-04 21:08:57   
186  1169301734725967872 2019-09-04 17:30:32   
187  1169291720837816321 2019-09-04 16:50:45   
188  1169253301138919424 2019-09-04 14:18:05   
189  1169253299981303810 2019-09-04 14:18:05   
190  1169253298169438208 2019-09-04 14:18:04   
191  1169249070990462978 2019-09-04 14:01:16   
192  1169249032197345281 2019-09-04 14:01:07   
193  1169248935447281665 2019-09-04 14:00:44   
194  1169246982508072960 2019-09-04 13:52:58   
195  1169062380040523776 2019-09-04 01:39:26   
196  1169062379134574592 2019-09-04 01:39:25   
197  1169053562904678405 2019-09-04 01:04:24   
198  1169050760098791431 2019-09-04 00:53:15   
199  1169048221026590725 2019-09-04 00:43:10   

                                                  text  
0    Leaving the White House soon to speak at the P...  
1    If it weren’t for the never ending Fake News a...  
2    ....This is a phony suppression poll, meant to...  
3    In a hypothetical poll, done by one of the wor...  
4    RT @AndrewPollackFL: Broward schools put this ...  
5    RT @MariaBartiromo: https://t.co/yMq3Eyiw7O @M...  
6    RT @MariaBartiromo: China is moving to develop...  
7    RT @realDonaldTrump: Greg Murphy won big, 62% ...  
8    RT @realDonaldTrump: BIG NIGHT FOR THE REPUBLI...  
9    ....The USA should always be paying the the lo...  
10   The Federal Reserve should get our interest ra...  
11                             https://t.co/WqBj8iMQhx  
12   “China suspends Tariffs on some U.S. products....  
13   Greg Murphy won big, 62% to 37%, in North Caro...  
14   Alice @alicetweet Stewart: Thank you for the n...  
15                             https://t.co/eK7swFWq1A  
16   RT @kevinomccarthy: GOP 2, Democrats 0 \n\nRev...  
17   .@CNN & @MSNBC were all set to have a BIG ...  
18   BIG NIGHT FOR THE REPUBLICAN PARTY. CONGRATULA...  
19   Greg Murphy is a big winner in North Carolina ...  
20   Dan Bishop was down 17 points 3 weeks ago. He ...  
21   Senator Ben Sasse has done a wonderful job rep...  
22   I am pleased to endorse Governor Mike Parson o...  
23   Excellent interview by @CondoleezzaRice on @Ma...  
24   One down, one to go – Greg Murphy is projected...  
25   Incredible progress being made at the Southern...  
26   RT @realDonaldTrump: Vote today for Dan Bishop...  
27   RT @realDonaldTrump: NORTH CAROLINA, VOTE FOR ...  
28   RT @realDonaldTrump: Last night in North Carol...  
29   ....I asked John for his resignation, which wa...  
..                                                 ...  
170  RT @militarykind: The announcer couldn't even ...  
171  Thank you Rad - looking great! https://t.co/Ye...  
172  Thank you Terrence. Best Employment Numbers In...  
173  RT @NHC_Atlantic: 7 pm Tropical Cyclone Update...  
174                            https://t.co/bxSiT2zQDj  
175  ....information does come out.” Charlie Hurt, ...  
176  ....facts, and that should terrify every Ameri...  
177  “Absolutely nothing is more important than goi...  
178  This was the originally projected path of the ...  
179  State Rep Greg Murphy is running for Congress ...  
180  RT @realDonaldTrump: The Great State of North ...  
181  7. The badly flawed Paris Climate Agreement pr...  
182  6. The Democrats’ destructive “environmental” ...  
183  4. The U.S. now leads the world in energy prod...  
184  1. Which country has the largest carbon emissi...  
185  8 FACTS that #FakeNewsCNN will ignore in tonig...  
186  RT @WhiteHouse: President @realDonaldTrump giv...  
187  RT @NHC_Atlantic: The Hurricane Warning has be...  
188  ....We can’t have a system where we run our en...  
189  ....Trump is doing to China is not lost on the...  
190  “The Chinese are very adept at not accepting a...  
191  RT @NHC_Atlantic: @NOAA @NWS Water levels coul...  
192  RT @NHC_Atlantic: Here's the latest #Dorian st...  
193  RT @NHC_Atlantic: The @NWSWPC has issued a Hig...  
194  “U.S. Winning Trade War With China In Dollars....  
195  .....on the President of the United States.” @...  
196  “To declassify is so important because if this...  
197  “I am so tired of hearing the rationalization ...  
198  The truth is that we have a nation that is dis...  
199  At the request of Senator Thom Tillis, I am ge...  

[200 rows x 3 columns]
In [127]:
#Import librabry
import tweepy
from tweepy import API
from tweepy import Cursor
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import cred
import pandas as pd
from tabulate import tabulate
import csv


class TwitterAuthenticator():
    def authenticate_twitter_app(self):        
        auth = OAuthHandler(cred.ckey, cred.csecret)
        auth.set_access_token(cred.atoken, cred.asecret)
        return auth

class TwitterStreamer():
    """
    Class for streaming and processing live tweets
    """
    def __init__(self):
        self.twitter_authenticator=TwitterAuthenticator()
    def stream_tweets(self, tweets_filename,hashtaglist):
        #This handles twitter authentication and the connection to the Twitter streaming API.
        listener=TwitterListener(tweets_filename)
        auth=self.twitter_authenticator.authenticate_twitter_app()
        #twitterStream = Stream(auth, listener)
        #Filtering the tweets we want to analyse
        #twitterStream.filter(track=hashtaglist)
        
        api = tweepy.API(auth) 
  
        # 200 tweets to be extracted 
        #number_of_tweets=2000
        ids=[]
        created_at=[]
        text=[]
        for status in tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump', tweet_mode="extended").items():
            #print(status)
            ids.append(status.id)
            created_at.append(status.created_at)
            text.append(status.full_text)
        
            
        #print(ids)
        #print(created_at)
        #print(text)
        
        #final=ids+created_at+text
        #print(final)
        table = pd.DataFrame(list(zip(ids,created_at,text)), columns=['id', 'created_at', 'text'])
        print(table)
        table.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\TrumpTweets1.csv')
        #tweet.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\a.csv')
        
class TwitterListener(StreamListener):#Inherited from StreamListener
    """
    Basic listner class to print and save the tweeets.
    """
    def __init__(self,tweets_filename):
        self.tweets_filename=tweets_filename
    def on_data(self, data): #Overridding class
        try:
            with open(self.tweets_filename,'a') as tf:
                tf.write(data)
            print(data)
            return True
        except BaseException as e:
            print("Error on_data: %s" %str(e))
            return True
    def on_error(self, status):
        if status==420:            
            #Return false on_data merhod in case we breach limits
            return False
        print(status)

if __name__=="__main__":# confirms that the code is under main function
    hashtaglist=["Article 370"]
    tweets_filename="tweet.json"
    ts=TwitterStreamer()
    ts.stream_tweets(tweets_filename,hashtaglist)
                     id          created_at  \
0   1171760702564052993 2019-09-11 12:21:36   
1   1171760235935125508 2019-09-11 12:19:45   
2   1171758532280143873 2019-09-11 12:12:58   
3   1171758531449643008 2019-09-11 12:12:58   
4   1171743257589690370 2019-09-11 11:12:17   
5   1171742213027586049 2019-09-11 11:08:08   
6   1171741981703311360 2019-09-11 11:07:13   
7   1171738781025746945 2019-09-11 10:54:29   
8   1171736398212272128 2019-09-11 10:45:01   
9   1171735692428419072 2019-09-11 10:42:13   
10  1171735691769929728 2019-09-11 10:42:13   
11  1171733174101131264 2019-09-11 10:32:13   
12  1171728799408500737 2019-09-11 10:14:50   
13  1171651786622537728 2019-09-11 05:08:48   
14  1171642393583656961 2019-09-11 04:31:29   
15  1171631144414208000 2019-09-11 03:46:47   
16  1171629221552283648 2019-09-11 03:39:08   
17  1171622285507289088 2019-09-11 03:11:35   
18  1171614032782123008 2019-09-11 02:38:47   
19  1171613145523195904 2019-09-11 02:35:16   
20  1171611976100917248 2019-09-11 02:30:37   
21  1171595113673347072 2019-09-11 01:23:36   
22  1171590284544827392 2019-09-11 01:04:25   
23  1171586554281615360 2019-09-11 00:49:36   
24  1171586230628311045 2019-09-11 00:48:19   
25  1171547046295171072 2019-09-10 22:12:36   
26  1171475308416884739 2019-09-10 17:27:33   
27  1171475286170292224 2019-09-10 17:27:27   
28  1171475240322383873 2019-09-10 17:27:16   
29  1171452881729228802 2019-09-10 15:58:26   
30  1171452880055746560 2019-09-10 15:58:25   
31  1171439301826994176 2019-09-10 15:04:28   
32  1171431074485817344 2019-09-10 14:31:46   
33  1171429005251104769 2019-09-10 14:23:33   
34  1171413029264732160 2019-09-10 13:20:04   
35  1171404283541164032 2019-09-10 12:45:19   
36  1171404220781793282 2019-09-10 12:45:04   
37  1171404116733640709 2019-09-10 12:44:39   
38  1171403919651680258 2019-09-10 12:43:52   
39  1171403844707913729 2019-09-10 12:43:34   

                                                 text  
0   Leaving the White House soon to speak at the P...  
1   If it weren’t for the never ending Fake News a...  
2   ....This is a phony suppression poll, meant to...  
3   In a hypothetical poll, done by one of the wor...  
4   RT @AndrewPollackFL: Broward schools put this ...  
5   RT @MariaBartiromo: https://t.co/yMq3Eyiw7O @M...  
6   RT @MariaBartiromo: China is moving to develop...  
7   RT @realDonaldTrump: Greg Murphy won big, 62% ...  
8   RT @realDonaldTrump: BIG NIGHT FOR THE REPUBLI...  
9   ....The USA should always be paying the the lo...  
10  The Federal Reserve should get our interest ra...  
11                            https://t.co/WqBj8iMQhx  
12  “China suspends Tariffs on some U.S. products....  
13  Greg Murphy won big, 62% to 37%, in North Caro...  
14  Alice @alicetweet Stewart: Thank you for the n...  
15                            https://t.co/eK7swFWq1A  
16  RT @kevinomccarthy: GOP 2, Democrats 0 \n\nRev...  
17  .@CNN & @MSNBC were all set to have a BIG ...  
18  BIG NIGHT FOR THE REPUBLICAN PARTY. CONGRATULA...  
19  Greg Murphy is a big winner in North Carolina ...  
20  Dan Bishop was down 17 points 3 weeks ago. He ...  
21  Senator Ben Sasse has done a wonderful job rep...  
22  I am pleased to endorse Governor Mike Parson o...  
23  Excellent interview by @CondoleezzaRice on @Ma...  
24  One down, one to go – Greg Murphy is projected...  
25  Incredible progress being made at the Southern...  
26  RT @realDonaldTrump: Vote today for Dan Bishop...  
27  RT @realDonaldTrump: NORTH CAROLINA, VOTE FOR ...  
28  RT @realDonaldTrump: Last night in North Carol...  
29  ....I asked John for his resignation, which wa...  
30  I informed John Bolton last night that his ser...  
31  Vote today for Dan Bishop. Will be great for N...  
32  One of the greatest and most powerful weapons ...  
33  ABC/Washington Post Poll was the worst and mos...  
34  NORTH CAROLINA, VOTE FOR DAN BISHOP TODAY. WE ...  
35  RT @Scavino45: 🚨Happening Now—\n@POTUS @realDo...  
36  RT @IvankaTrump: In August, the African Americ...  
37  RT @realDonaldTrump: Received an update on Air...  
38  RT @mike_pence: Thrilled to be here in the gre...  
39  RT @mike_pence: It has been two and a half yea...  
In [136]:
import pandas as pd
data = pd.read_csv("TrumpTweets.csv") 
print(data)
     Unnamed: 0                   id           created_at  \
0             0  1171760702564052993  2019-09-11 12:21:36   
1             1  1171760235935125508  2019-09-11 12:19:45   
2             2  1171758532280143873  2019-09-11 12:12:58   
3             3  1171758531449643008  2019-09-11 12:12:58   
4             4  1171743257589690370  2019-09-11 11:12:17   
5             5  1171742213027586049  2019-09-11 11:08:08   
6             6  1171741981703311360  2019-09-11 11:07:13   
7             7  1171738781025746945  2019-09-11 10:54:29   
8             8  1171736398212272128  2019-09-11 10:45:01   
9             9  1171735692428419072  2019-09-11 10:42:13   
10           10  1171735691769929728  2019-09-11 10:42:13   
11           11  1171733174101131264  2019-09-11 10:32:13   
12           12  1171728799408500737  2019-09-11 10:14:50   
13           13  1171651786622537728  2019-09-11 05:08:48   
14           14  1171642393583656961  2019-09-11 04:31:29   
15           15  1171631144414208000  2019-09-11 03:46:47   
16           16  1171629221552283648  2019-09-11 03:39:08   
17           17  1171622285507289088  2019-09-11 03:11:35   
18           18  1171614032782123008  2019-09-11 02:38:47   
19           19  1171613145523195904  2019-09-11 02:35:16   
20           20  1171611976100917248  2019-09-11 02:30:37   
21           21  1171595113673347072  2019-09-11 01:23:36   
22           22  1171590284544827392  2019-09-11 01:04:25   
23           23  1171586554281615360  2019-09-11 00:49:36   
24           24  1171586230628311045  2019-09-11 00:48:19   
25           25  1171547046295171072  2019-09-10 22:12:36   
26           26  1171475308416884739  2019-09-10 17:27:33   
27           27  1171475286170292224  2019-09-10 17:27:27   
28           28  1171475240322383873  2019-09-10 17:27:16   
29           29  1171452881729228802  2019-09-10 15:58:26   
..          ...                  ...                  ...   
170         170  1169571407816253441  2019-09-05 11:22:07   
171         171  1169459039132102657  2019-09-05 03:55:37   
172         172  1169455923712221185  2019-09-05 03:43:14   
173         173  1169447181872521218  2019-09-05 03:08:30   
174         174  1169415182029901824  2019-09-05 01:01:20   
175         175  1169412199611326464  2019-09-05 00:49:29   
176         176  1169412198692732928  2019-09-05 00:49:29   
177         177  1169412197841350657  2019-09-05 00:49:29   
178         178  1169375550806351872  2019-09-04 22:23:51   
179         179  1169366511439552512  2019-09-04 21:47:56   
180         180  1169360837498351618  2019-09-04 21:25:23   
181         181  1169356705857187840  2019-09-04 21:08:58   
182         182  1169356704926109696  2019-09-04 21:08:58   
183         183  1169356704028516353  2019-09-04 21:08:58   
184         184  1169356703126773762  2019-09-04 21:08:58   
185         185  1169356701943894017  2019-09-04 21:08:57   
186         186  1169301734725967872  2019-09-04 17:30:32   
187         187  1169291720837816321  2019-09-04 16:50:45   
188         188  1169253301138919424  2019-09-04 14:18:05   
189         189  1169253299981303810  2019-09-04 14:18:05   
190         190  1169253298169438208  2019-09-04 14:18:04   
191         191  1169249070990462978  2019-09-04 14:01:16   
192         192  1169249032197345281  2019-09-04 14:01:07   
193         193  1169248935447281665  2019-09-04 14:00:44   
194         194  1169246982508072960  2019-09-04 13:52:58   
195         195  1169062380040523776  2019-09-04 01:39:26   
196         196  1169062379134574592  2019-09-04 01:39:25   
197         197  1169053562904678405  2019-09-04 01:04:24   
198         198  1169050760098791431  2019-09-04 00:53:15   
199         199  1169048221026590725  2019-09-04 00:43:10   

                                                  text  
0    Leaving the White House soon to speak at the P...  
1    If it weren’t for the never ending Fake News a...  
2    ....This is a phony suppression poll, meant to...  
3    In a hypothetical poll, done by one of the wor...  
4    RT @AndrewPollackFL: Broward schools put this ...  
5    RT @MariaBartiromo: https://t.co/yMq3Eyiw7O @M...  
6    RT @MariaBartiromo: China is moving to develop...  
7    RT @realDonaldTrump: Greg Murphy won big, 62% ...  
8    RT @realDonaldTrump: BIG NIGHT FOR THE REPUBLI...  
9    ....The USA should always be paying the the lo...  
10   The Federal Reserve should get our interest ra...  
11                             https://t.co/WqBj8iMQhx  
12   “China suspends Tariffs on some U.S. products....  
13   Greg Murphy won big, 62% to 37%, in North Caro...  
14   Alice @alicetweet Stewart: Thank you for the n...  
15                             https://t.co/eK7swFWq1A  
16   RT @kevinomccarthy: GOP 2, Democrats 0 \n\nRev...  
17   .@CNN & @MSNBC were all set to have a BIG ...  
18   BIG NIGHT FOR THE REPUBLICAN PARTY. CONGRATULA...  
19   Greg Murphy is a big winner in North Carolina ...  
20   Dan Bishop was down 17 points 3 weeks ago. He ...  
21   Senator Ben Sasse has done a wonderful job rep...  
22   I am pleased to endorse Governor Mike Parson o...  
23   Excellent interview by @CondoleezzaRice on @Ma...  
24   One down, one to go – Greg Murphy is projected...  
25   Incredible progress being made at the Southern...  
26   RT @realDonaldTrump: Vote today for Dan Bishop...  
27   RT @realDonaldTrump: NORTH CAROLINA, VOTE FOR ...  
28   RT @realDonaldTrump: Last night in North Carol...  
29   ....I asked John for his resignation, which wa...  
..                                                 ...  
170  RT @militarykind: The announcer couldn't even ...  
171  Thank you Rad - looking great! https://t.co/Ye...  
172  Thank you Terrence. Best Employment Numbers In...  
173  RT @NHC_Atlantic: 7 pm Tropical Cyclone Update...  
174                            https://t.co/bxSiT2zQDj  
175  ....information does come out.” Charlie Hurt, ...  
176  ....facts, and that should terrify every Ameri...  
177  “Absolutely nothing is more important than goi...  
178  This was the originally projected path of the ...  
179  State Rep Greg Murphy is running for Congress ...  
180  RT @realDonaldTrump: The Great State of North ...  
181  7. The badly flawed Paris Climate Agreement pr...  
182  6. The Democrats’ destructive “environmental” ...  
183  4. The U.S. now leads the world in energy prod...  
184  1. Which country has the largest carbon emissi...  
185  8 FACTS that #FakeNewsCNN will ignore in tonig...  
186  RT @WhiteHouse: President @realDonaldTrump giv...  
187  RT @NHC_Atlantic: The Hurricane Warning has be...  
188  ....We can’t have a system where we run our en...  
189  ....Trump is doing to China is not lost on the...  
190  “The Chinese are very adept at not accepting a...  
191  RT @NHC_Atlantic: @NOAA @NWS Water levels coul...  
192  RT @NHC_Atlantic: Here's the latest #Dorian st...  
193  RT @NHC_Atlantic: The @NWSWPC has issued a Hig...  
194  “U.S. Winning Trade War With China In Dollars....  
195  .....on the President of the United States.” @...  
196  “To declassify is so important because if this...  
197  “I am so tired of hearing the rationalization ...  
198  The truth is that we have a nation that is dis...  
199  At the request of Senator Thom Tillis, I am ge...  

[200 rows x 4 columns]
In [11]:
#Import librabry
import tweepy
from tweepy import API
from tweepy import Cursor
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import cred
import pandas as pd
from tabulate import tabulate
import csv


class TwitterAuthenticator():
    def authenticate_twitter_app(self):        
        auth = OAuthHandler(cred.ckey, cred.csecret)
        auth.set_access_token(cred.atoken, cred.asecret)
        return auth

class TwitterStreamer():
    """
    Class for streaming and processing live tweets
    """
    def __init__(self):
        self.twitter_authenticator=TwitterAuthenticator()
    def stream_tweets(self, tweets_filename,hashtaglist):
        #This handles twitter authentication and the connection to the Twitter streaming API.
        listener=TwitterListener(tweets_filename)
        auth=self.twitter_authenticator.authenticate_twitter_app()
        #twitterStream = Stream(auth, listener)
        #Filtering the tweets we want to analyse
        #twitterStream.filter(track=hashtaglist)
        
        api = tweepy.API(auth) 
  
        # 200 tweets to be extracted 
        #number_of_tweets=2000
        #tweets = api.user_timeline(screen_name="realDonaldTrump",max_id=1170469619154530305,count=2, tweet_mode="extended") 
        tweets = api.user_timeline(screen_name="realDonaldTrump",since_id=1173571513418756098,count=10000, tweet_mode="extended") 
        #cols = ['id', 'created_at', 'full_text', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'retweeted',
         #       'retweet_count', 'favorited', 'favorite_count', 'source']
        cols = ['id', 'created_at', 'full_text', 'retweet_count','favorite_count']
        #print(tweets)

        tweet = [[getattr(t, x) for x in cols] for t in tweets]
        
        ids=[]
        created_at=[]
        text=[]
        retweet_count=[]
        favorite_count=[]
        for row in tweet:
            ids.append(row[0])
            created_at.append(row[1])
            text.append(row[2])
            retweet_count.append(row[3])
            favorite_count.append(row[4])
            
        #print(ids)
        #print(created_at)
        #print(text)
        
        #final=ids+created_at+text
        #print(final)
        table = pd.DataFrame(list(zip(ids,created_at,text,retweet_count,favorite_count)), columns=cols)
        print(table)
        #print(table[table['text'].str.contains('kill')])
        table.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\TrumpTweetsTest.csv')
        #tweet.to_csv(r'C:\Users\v-shdash\Desktop\Twitter\a.csv')
        
class TwitterListener(StreamListener):#Inherited from StreamListener
    """
    Basic listner class to print and save the tweeets.
    """
    def __init__(self,tweets_filename):
        self.tweets_filename=tweets_filename
    def on_data(self, data): #Overridding class
        try:
            with open(self.tweets_filename,'a') as tf:
                tf.write(data)
            print(data)
            return True
        except BaseException as e:
            print("Error on_data: %s" %str(e))
            return True
    def on_error(self, status):
        if status==420:            
            #Return false on_data merhod in case we breach limits
            return False
        print(status)

if __name__=="__main__":# confirms that the code is under main function
    hashtaglist=["Article 370"]
    tweets_filename="tweet.json"
    ts=TwitterStreamer()
    ts.stream_tweets(tweets_filename,hashtaglist)
                     id          created_at  \
0   1173806093635444736 2019-09-17 03:49:15   
1   1173804280190390272 2019-09-17 03:42:03   
2   1173803449202249728 2019-09-17 03:38:45   
3   1173755864529821697 2019-09-17 00:29:40   
4   1173755859005952001 2019-09-17 00:29:38   
5   1173738748388921344 2019-09-16 23:21:39   
6   1173730721514409984 2019-09-16 22:49:45   
7   1173730406366973952 2019-09-16 22:48:30   
8   1173728490618671106 2019-09-16 22:40:53   
9   1173728487162540032 2019-09-16 22:40:52   
10  1173716500781256704 2019-09-16 21:53:15   
11  1173706388960239616 2019-09-16 21:13:04   
12  1173703009609637888 2019-09-16 20:59:38   
13  1173700920166748166 2019-09-16 20:51:20   
14  1173700878689325063 2019-09-16 20:51:10   
15  1173700810271875079 2019-09-16 20:50:54   
16  1173679666047135745 2019-09-16 19:26:52   
17  1173677124076613632 2019-09-16 19:16:46   
18  1173672361670975490 2019-09-16 18:57:51   
19  1173657585653866498 2019-09-16 17:59:08   
20  1173597715487477760 2019-09-16 14:01:14   
21  1173597713860046848 2019-09-16 14:01:14   
22  1173591284969332736 2019-09-16 13:35:41   
23  1173586320943456258 2019-09-16 13:15:57   
24  1173576122811985920 2019-09-16 12:35:26   

                                            full_text  retweet_count  \
0   If you want to stop the drug smugglers, human ...          10175   
1   We are all united by the same love of Country,...          12578   
2   Beautiful evening in New Mexico with Great Ame...           9199   
3   RT @WhiteHouse: Oil production is up an incred...           5807   
4   RT @WhiteHouse: Business creation is thriving ...           4292   
5   RT @FLOTUS: Proud to recognize Mariano Rivera ...           8708   
6         KEEP AMERICA GREAT! https://t.co/oPWfjSGW22          14547   
7   On my way to New Mexico — see you all shortly ...           8005   
8   ...She can never recover, and will never retur...          12656   
9   I call for the Resignation of everybody at The...          23216   
10  RT @WhiteHouse: Earlier: President @realDonald...           4697   
11  “How many stories are wrong? Almost all of the...          12661   
12  Congratulations @MarianoRivera! https://t.co/e...           9690   
13  RT @GovRicketts: It's time for Congress to sea...           4921   
14  RT @GovBillLee: The USMCA is a 21st-century tr...           4115   
15  RT @GovAbbott: The #USMCA is essential to the ...           4662   
16  This afternoon at the @WhiteHouse, it was my g...           8081   
17  Thank you, working hard! #KAG2020 https://t.co...           9653   
18  Big crowd expected in New Mexico tonight, wher...          11037   
19  In a short while I will be presenting the New ...           8297   
20  ....for the privilege of being your President ...          18157   
21  They failed on the Mueller Report, they failed...          19578   
22  “Democrats would rather talk about gun control...          10422   
23  Remember when Iran shot down a drone, saying k...          18780   
24  Just Out: “Kavanaugh accuser doesn’t recall in...          19147   

    favorite_count  
0            35520  
1            47447  
2            33464  
3                0  
4                0  
5                0  
6            60021  
7            31939  
8            58335  
9            91358  
10               0  
11           46473  
12           41097  
13               0  
14               0  
15               0  
16           34145  
17           42393  
18           41322  
19           40789  
20           73751  
21           79761  
22           40440  
23           75127  
24           66179  
In [279]:
import pandas as pd
data = pd.read_csv("TrumpTweets.csv") 
del data['Unnamed: 0']
tweets=data.sort_values('created_at',ascending=False)
#print(tweets.head(n=3))
print(tweets['full_text'])
print(tweets['full_text'].str.contains('â'))
#print(tweets[tweets['text'].str.contains('|')])
#print(tweets['text'].str.rfind("|"))
#print(tweets['text'].str[:tweets['text'].str.rfind("|")])
0      “This should have been over with after the Mue...
1      “We can’t beat him, so lets impeach him!” Demo...
2      “Dems have never gotten over the fact that Pre...
3       Some really big Court wins on the Border lately!
4      It is expected that China will be buying large...
5      European Central Bank, acting quickly, Cuts Ra...
6      RT @SecPompeo: The U.S. joins 11 partner natio...
7      RT @parscale: Socialism SUCKS and @TeamTrump i...
8      RT @PrisonPlanet: A ship carrying passengers w...
9      RT @IsraelUSAforevr: @realDonaldTrump  https:/...
10            Thank you Brandon! https://t.co/VfzWVHYIrU
11                    Thank you! https://t.co/zKSrmhsBhW
12     The Wall is going up very fast despite total O...
13     RT @Jim_Jordan: The House Judiciary Committee ...
14     The Wall is being built after victories agains...
15     RT @VP: The #USMCA is a deal for the 21st Cent...
16     RT @VP: The #USMCA is the modern trade deal th...
17     RT @VP: The #USMCA means:\n✅ Stronger Economic...
18     RT @VP: Not only will the #USMCA benefit Ameri...
19     RT @Jim_Jordan: When will the Judiciary Commit...
20     RT @LaraLeaTrump: Congrats on the new book, @t...
21     RT @lopezobrador_: Sostuvimos una buena conver...
22     ....The Southern Border is becoming very stron...
23     I had an excellent telephone conversation with...
25     At the request of the Vice Premier of China, L...
24     ....on October 1st, we have agreed, as a gestu...
26     BIG United States Supreme Court WIN for the Bo...
27     Today and every day, we pledge to honor our hi...
28     RT @dougmillsnyt: .\n@realDonaldTrump & @F...
29     RT @WhiteHouse: On September 11, 2001, the wor...
                             ...                        
170    ....President Obama never had the legal right ...
171    ....have the discretion to end the program tha...
172    The Immigration Law Institute’s Christopher Ha...
173    RT @NHC_Atlantic: Here's the 1am EDT update on...
174    RT @NHC_Atlantic: Hurricane #Dorian Advisory 5...
176    “I think President Trump is set in his ways be...
175    ....that our economy is very strong. If the Fe...
177    RT @MadMoneyOnCNBC: .@JimCramer: Thursday’s po...
178    Looking forward to watching @SarahHuckabee San...
179    Great job done by @GovRonDesantis, @SenRickSco...
180    Just got off the phone with Governor Brian Kem...
181    Just spoke to Governor @HenryMcMaster of South...
182    Just talked to Governor Roy Cooper of North Ca...
183    RT @NHC_Atlantic: Here are the 5pm EDT Key Mes...
184    I was with you all the way Alabama. The Fake N...
185    Just as I said, Alabama was originally project...
186    RT @NWSColumbia: [Sep 5, 1`:25 PM] - Winds are...
187    RT @NHC_Atlantic: Here are the 11 am EDT key m...
189    After almost 3 years in my Administration, Jas...
188    ....His dedication to Israel and to seeking pe...
190                            Really Good Jobs Numbers!
191    Alabama was going to be hit or grazed, and the...
192    ....said what she did, even being on a much hi...
193    Bad “actress” Debra The Mess Messing is in hot...
194    RT @NHC_Atlantic: Beyond Hurricane #Dorian and...
195    RT @NWSWilmingtonNC: Video of a tornado passin...
196    RT @NHC_Atlantic: 7 AM EDT Tropical Cyclone Up...
197    RT @DaveNYviii: President Trump Border Update ...
198    RT @realDonaldTrump: This was the originally p...
199    ....Instead it turned North and went up the co...
Name: full_text, Length: 200, dtype: object
0      False
1      False
2      False
3      False
4      False
5      False
6      False
7      False
8      False
9      False
10     False
11     False
12     False
13     False
14     False
15     False
16     False
17     False
18     False
19     False
20     False
21     False
22     False
23     False
25     False
24     False
26     False
27     False
28     False
29     False
       ...  
170    False
171    False
172    False
173    False
174    False
176    False
175    False
177    False
178    False
179    False
180    False
181    False
182    False
183    False
184    False
185    False
186    False
187    False
189    False
188    False
190    False
191    False
192    False
193    False
194    False
195    False
196    False
197    False
198    False
199    False
Name: full_text, Length: 200, dtype: bool
In [ ]:
 
In [ ]:
 

No comments:

Post a Comment