I am learning the tweepy library to access the twitter api. I have a csv file with some preliminary data (such as tweet_id) and I pulled that into a dataframe. I need to use that data to pull more data using tweepy.
I am trying to write that data to a text file and then create a new dataframe off of that. I have been trying different things the past couple evenings, and I don't understand why this isn't writing the data to the text file. I have all the necessary tokens stored in variables.
auth = tweepy.OAuthHandler(Consumer_Key, Consumer_Secret)
auth.set_access_token(Access_Token, Access_Secret)
tweetapi = tweepy.API(auth,
wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
#writing text file
txtfile = open("jsontweet3.txt", "a")
txtfile.write('tweet_id retweet_count favorite_count''\n')
#pulling tweet info
for tweet_id in fdf.tweet_id:
try:
twitinfo = tweetapi.get_status(str(tweet_id),tweet_mode='extended')
retweets = twitinfo.retweet_count
favorites = twitinfo.favorite_count
txtfile.write(twitinfo+' '+str(retweets)+' '+str(favorites)+'\n')
txtfile.close()
I would be greatly appreciative of any help!