vladkens / twscrape

2024! X / Twitter API scrapper with authorization support. Allows you to scrape search results, User's profiles (followers/following), Tweets (favoriters/retweeters) and more.
https://pypi.org/project/twscrape/
MIT License
1.13k stars 132 forks source link

Getting Most Recent Tweet #129

Closed FroostySnoowman closed 7 months ago

FroostySnoowman commented 9 months ago

Hello, what's the best option to get the most recent tweet? I've done something like:

        async for tweet in api.user_tweets(flash_twitter_id, limit=1):
            ...
            break

However, that seems to be inconsistent. Is there a better way to do this?

agrieco commented 9 months ago

This seems like the best/only way.

A few notes: 1) this will return an unsorted list of the latest tweets. Here is a snippet for re-ordering them so they are sorted.

sorted_tweets=sorted(tweets,key=lambda x: x.id) # the API returns unordered tweets.  this should order them by id 

2) I've had to write code to keep up with the 'last' tweet id to figure out if the function is returning 'new to my code' tweets. I'm unaware of a better way to do this- open to ideas.

malone6 commented 9 months ago

Your code is right. This will return to the latest page of the user's homepage like the web, it should be noted that is one page's tweets(about 20 tweets) rather than one tweet. More than 20 tweets in reality(about 30~40), as it includes additional system recommendations and ads, so you can get the latest one among them

heyeanne34 commented 9 months ago

Your code is right. This will return to the latest page of the user's homepage like the web, it should be noted that is one page's tweets(about 20 tweets) rather than one tweet. More than 20 tweets in reality(about 30~40), as it includes additional system recommendations and ads, so you can get the latest one among them

hi how to contact you since ive been trying for a month making this repository work but i couldnt

malone6 commented 9 months ago

Your code is right. This will return to the latest page of the user's homepage like the web, it should be noted that is one page's tweets(about 20 tweets) rather than one tweet. More than 20 tweets in reality(about 30~40), as it includes additional system recommendations and ads, so you can get the latest one among them

hi how to contact you since ive been trying for a month making this repository work but i couldnt

You can send a email to me. My email address is on my Github profile.

heyeanne34 commented 8 months ago

Your code is right. This will return to the latest page of the user's homepage like the web, it should be noted that is one page's tweets(about 20 tweets) rather than one tweet. More than 20 tweets in reality(about 30~40), as it includes additional system recommendations and ads, so you can get the latest one among them

hi how to contact you since ive been trying for a month making this repository work but i couldnt

You can send a email to me. My email address is on my Github profile.

hello ive sent an email

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 5 days with no activity.