[+] Get all tweets from a specific user in a loop
This commit is contained in:
+11
-9
@@ -9,7 +9,7 @@ import tweepy
|
|||||||
from tweepy import API
|
from tweepy import API
|
||||||
from tweepy.models import Status
|
from tweepy.models import Status
|
||||||
|
|
||||||
from collect.utils import Config
|
from collect.utils import Config, Posting, debug
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -80,13 +80,15 @@ def get_user_tweets(api: API, screen_name: str) -> list[Tweet]:
|
|||||||
:param screen_name: Screen name of that individual
|
:param screen_name: Screen name of that individual
|
||||||
:return: All tweets
|
:return: All tweets
|
||||||
"""
|
"""
|
||||||
tweets = api.user_timeline(screen_name=screen_name, count=200, tweet_mode='extended')
|
debug(f'Getting user tweets for {screen_name}')
|
||||||
# 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))
|
|
||||||
|
|
||||||
|
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
|
return tweets
|
||||||
|
|||||||
@@ -14,6 +14,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
tweets = get_user_tweets(api, 'voxdotcom')
|
tweets = get_user_tweets(api, 'voxdotcom')
|
||||||
|
|
||||||
for tweet in tweets:
|
print(len(tweets))
|
||||||
print(tweet)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user