[+] Get all tweets from a specific user in a loop

This commit is contained in:
Hykilpikonna
2021-11-03 16:45:30 -04:00
parent ae885317a1
commit 37bbe4f5b0
2 changed files with 12 additions and 11 deletions
+11 -9
View File
@@ -9,7 +9,7 @@ import tweepy
from tweepy import API
from tweepy.models import Status
from collect.utils import Config
from collect.utils import Config, Posting, debug
@dataclass
@@ -80,13 +80,15 @@ def get_user_tweets(api: API, screen_name: str) -> list[Tweet]:
:param screen_name: Screen name of that individual
:return: All tweets
"""
tweets = api.user_timeline(screen_name=screen_name, count=200, tweet_mode='extended')
# parsed_tweets: list[Tweet] = []
#
# for tweet in tweets:
# json_str = str(tweet._json).replace("\"", "\\\"").replace('\'', '\"')
# print(tweet._json)
# obj = demjson.decode(str(tweet._json))
# parsed_tweets.append(Tweet(**obj))
debug(f'Getting user tweets for {screen_name}')
tweets: list[Tweet] = api.user_timeline(screen_name=screen_name, count=200, tweet_mode='extended')
while True:
debug(f'- Got {len(tweets)} tweets, getting additional tweets...')
additional_tweets = api.user_timeline(screen_name=screen_name, count=200, tweet_mode='extended', max_id=tweets[-1].id)
if len(additional_tweets) == 0:
break
tweets.extend(additional_tweets)
debug(f'- Got {len(tweets)} tweets, finished.')
return tweets
+1 -2
View File
@@ -14,6 +14,5 @@ if __name__ == '__main__':
tweets = get_user_tweets(api, 'voxdotcom')
for tweet in tweets:
print(tweet)
print(len(tweets))