From de2be0b7af65ae1cc9c8bf96ae1304294718af9d Mon Sep 17 00:00:00 2001 From: Alex Huddleston Date: Wed, 13 Feb 2019 17:33:56 -0600 Subject: [PATCH] small progress. --- tweet_downloader.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tweet_downloader.py b/tweet_downloader.py index adb749c..533a824 100644 --- a/tweet_downloader.py +++ b/tweet_downloader.py @@ -4,7 +4,7 @@ # Some legacy code I wrote for a project in college. It's ugly and messy. I'll clean it up and repurpose it later. import tweepy #https://github.com/tweepy/tweepy -import csv +import json from time import sleep @@ -23,13 +23,14 @@ def get_all_tweets(screen_name): api = tweepy.API(auth) #initialize a list to hold all the tweepy Tweets - alltweets = [] + recent_tweets = [] #make initial request for most recent tweets (200 is the maximum allowed count) - new_tweets = api.user_timeline(screen_name = screen_name,count=200,tweet_mode = 'extended') + new_tweets = api.user_timeline(screen_name = screen_name,count=10,tweet_mode = 'extended') #save most recent tweets - alltweets.extend(new_tweets) + recent_tweets.extend(new_tweets) + ''' #save the id of the oldest tweet less one oldest = alltweets[-1].id - 1 @@ -49,9 +50,10 @@ def get_all_tweets(screen_name): print("...%s tweets downloaded so far" % (len(alltweets))) + ''' #transform the tweepy tweets into a 2D array that will populate the csv outtweets = [] - for tweet in alltweets: + for tweet in recent_tweets: try: if tweet.retweeted or ('RT @' in tweet.text): outtweets.append([tweet.id_str, tweet.created_at, "True", tweet.retweeted_status.text.encode("utf-8"), tweet.entities.get('hashtags'), tweet.entities.get('user_mentions')]) @@ -61,6 +63,10 @@ def get_all_tweets(screen_name): except: outtweets.append([tweet.id_str, tweet.created_at, ('RT @' in tweet.text), tweet.text.encode("utf-8"), tweet.entities.get('hashtags'), tweet.entities.get('user_mentions')]) + for t in outtweets: + print(t[3]) + + ''' #write the csv with open('%s_tweets.csv' % screen_name, 'w') as f: writer = csv.writer(f) @@ -68,7 +74,14 @@ def get_all_tweets(screen_name): writer.writerows(outtweets) pass + ''' +if __name__ == '__main__': + with open('users.txt', 'r') as f: + for l in f: + get_all_tweets(l.rstrip()) + +''' if __name__ == '__main__': #pass in the username of the account you want to download @@ -79,3 +92,5 @@ if __name__ == '__main__': counter = counter + 1 if (counter % 5) == 0: sleep(15*60) + +'''