small progress.
This commit is contained in:
parent
3c635464d8
commit
de2be0b7af
1 changed files with 20 additions and 5 deletions
|
@ -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.
|
# 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 tweepy #https://github.com/tweepy/tweepy
|
||||||
import csv
|
import json
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,13 +23,14 @@ def get_all_tweets(screen_name):
|
||||||
api = tweepy.API(auth)
|
api = tweepy.API(auth)
|
||||||
|
|
||||||
#initialize a list to hold all the tweepy Tweets
|
#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)
|
#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
|
#save most recent tweets
|
||||||
alltweets.extend(new_tweets)
|
recent_tweets.extend(new_tweets)
|
||||||
|
'''
|
||||||
|
|
||||||
#save the id of the oldest tweet less one
|
#save the id of the oldest tweet less one
|
||||||
oldest = alltweets[-1].id - 1
|
oldest = alltweets[-1].id - 1
|
||||||
|
@ -49,9 +50,10 @@ def get_all_tweets(screen_name):
|
||||||
|
|
||||||
print("...%s tweets downloaded so far" % (len(alltweets)))
|
print("...%s tweets downloaded so far" % (len(alltweets)))
|
||||||
|
|
||||||
|
'''
|
||||||
#transform the tweepy tweets into a 2D array that will populate the csv
|
#transform the tweepy tweets into a 2D array that will populate the csv
|
||||||
outtweets = []
|
outtweets = []
|
||||||
for tweet in alltweets:
|
for tweet in recent_tweets:
|
||||||
try:
|
try:
|
||||||
if tweet.retweeted or ('RT @' in tweet.text):
|
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')])
|
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:
|
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')])
|
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
|
#write the csv
|
||||||
with open('%s_tweets.csv' % screen_name, 'w') as f:
|
with open('%s_tweets.csv' % screen_name, 'w') as f:
|
||||||
writer = csv.writer(f)
|
writer = csv.writer(f)
|
||||||
|
@ -68,7 +74,14 @@ def get_all_tweets(screen_name):
|
||||||
writer.writerows(outtweets)
|
writer.writerows(outtweets)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
'''
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with open('users.txt', 'r') as f:
|
||||||
|
for l in f:
|
||||||
|
get_all_tweets(l.rstrip())
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#pass in the username of the account you want to download
|
#pass in the username of the account you want to download
|
||||||
|
@ -79,3 +92,5 @@ if __name__ == '__main__':
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
if (counter % 5) == 0:
|
if (counter % 5) == 0:
|
||||||
sleep(15*60)
|
sleep(15*60)
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
Reference in a new issue