Add method for getting tweets with replies

This commit is contained in:
2025-01-30 02:12:54 +13:00
parent a81a461da2
commit 49df46ccf9
2 changed files with 129 additions and 41 deletions

View File

@ -25,7 +25,7 @@ csrf_token = os.environ["CSRF_TOKEN"]
scraper = TweetsScraper(auth_token, csrf_token)
user_id = scraper.get_id_from_screen_name("pobnellion")
user_id = scraper.get_id_from_handle("pobnellion")
user_tweets = scraper.get_tweets(user_id, 100)
```
@ -39,9 +39,20 @@ AUTH_TOKEN=<auth token>
CSRF_TOKEN=<csrf token>
```
You can find your auth and csrf tokens in twitter's cookies (F12 in your browser > storage tab > cookies)
The auth token cookie is called `auth_token` and the csrf token is called `ct0`
#### Include replies
```
user_id = scraper.get_id_from_handle("@pobnellion")
user_tweets = scraper.get_tweets_and_replies(user_id, 100)
```
This is equivalent to viewing the 'replies' tab on twitter, replies show up as Conversation objects which contain a list of tweets.
The last tweet in the conversation will always be by the currently viewed user, even if there are more replies in the chain.
### Tweet object
Contains the text of the tweet, along with the timestamp and some stats (like count, repost count, views, etc)
@ -54,7 +65,33 @@ Contains the text of the tweet, along with the timestamp and some stats (like co
- retweets : retweet count
- quotes : quite tweet count
- date : post date
- is_retweet: tweet is a retweet
- is_quote: tweet is a quote tweet
- user: user who sent tweet (this is useful in conversations)
Printing a tweet object results in an overview:
`L:52 RT:2 Q:1 R:3 V:1032 2025-01-20T01:53:57+00:00 Example tweet text`
### Conversation object
Container for a list of tweets as shown when viewing the replies tab. Does not have any other information
#### Fields
- items : list of tweets in the conversation
### User object
Twitter user
#### Fields
- id : user id
- handle : user handle (without @)
- display_name :
- description :
- join_date :
- location :
- tweets_count :
- blue_verified :
- follower_count :