Update 1.Twitter_Extraction.py

parent ca25e84a
import tweepy import tweepy
import sys import sys
import datetime, time import datetime, time
import pandas
import CV_Importer
'''
consumer_key = 'fhraYITA4gYHYWmzPURwC4FUF' consumer_key = 'fhraYITA4gYHYWmzPURwC4FUF'
consumer_secret = 'SlaKflVA1TVpDqGKGAmybFHzLCjirpAxU0M4PbcDfUT89ymv5v' consumer_secret = 'SlaKflVA1TVpDqGKGAmybFHzLCjirpAxU0M4PbcDfUT89ymv5v'
access_token = '1360183307099537417-SZsSEgZINJriZ8RCGaXYQ4vuIC02Cp' access_token = '1360183307099537417-SZsSEgZINJriZ8RCGaXYQ4vuIC02Cp'
access_secret = 'V2mEDysZyqxdNlU0JDGlyw89seNe9g3PZn0YZNBmd5bk6' access_secret = 'V2mEDysZyqxdNlU0JDGlyw89seNe9g3PZn0YZNBmd5bk6'
'''
consumer_key = 'UxSccbbFTpX0pWjQCEHz4nNVR'
consumer_secret = 'L2KjSPLai7yiY0r4mjaUGV344GH1oWm5psU7LORBEryutWBwdV'
access_token = '867670407599579137-1z7XALKr1OKHR88wgs2x3Izs3QE8fVS'
access_secret = 'Itf4qhWAkSvfFDtelQPPvTNGLG5bf6OrycQ1N1UJZQjzL'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret) auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth) api = tweepy.API(auth)
tweet_file = open("Tweet.txt", "w") tweet_file = open("Tweet.txt", "w")
def deleteContent(pfile): def deleteContent(pfile):
pfile.seek(0) pfile.seek(0)
...@@ -18,6 +29,7 @@ def deleteContent(pfile): ...@@ -18,6 +29,7 @@ def deleteContent(pfile):
deleteContent(tweet_file) deleteContent(tweet_file)
def get_tweets(api, username): def get_tweets(api, username):
page = 1 page = 1
deadend = False deadend = False
...@@ -26,21 +38,23 @@ def get_tweets(api, username): ...@@ -26,21 +38,23 @@ def get_tweets(api, username):
tweets = api.user_timeline(username, page = page) tweets = api.user_timeline(username, page = page)
for tweet in tweets: for tweet in tweets:
if (datetime.datetime.now() - tweet.created_at).days < 365: if (datetime.datetime.now() - tweet.created_at).days < 365:
tweets = (tweet.text.encode('utf-8')) tweets = (tweet.text)
with open('Tweet.txt', 'a') as the_file: #with open('Tweet.txt', 'a') as the_file:
the_file.write(str(tweets) + '\n') #the_file.write(str(tweets) + '\n')
#with open("Tweet.txt", "a", encoding="utf-8") as f: with open("Tweet.txt", "a", encoding="utf-8") as f:
#f.write(tweets) f.write(tweets + '\n')
print(tweets) print(tweets)
else: else:
deadend = True deadend = True
return return
if not deadend: if not deadend:
page = page + 1 page = page + 1
if(page == 10): if(page == 5):
return return
user = input("Enter name : ") ID = open('TwitterID.txt', 'r')
user = ID.read()
print("Twitter ID : " + user + " \n")
get_tweets(api, user) get_tweets(api, user)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment