Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving tweets in chronological order using tweepy for python

I have written a Python script that uploads 6 URL's in each tweet to Twitter. I use the user_timeline() API call to pull down all the posts that are made, effectively shortening the URL's that I posted to twitters t.co URL's.

My problem is that the user_timeline() call does not order the tweets chronologically.

In a Twitter timeline the most recent tweet is posted at the top. I would prefer it, if I could read back the timeline from the bottom, which is where my first tweet would start.

This is the code I'm using to retrieve the tweets on my timeline from twitter:

user_tweets = api.user_timeline()
for tweet in user_tweets:
    print tweet.text

Does anyone have an idea of how I can use tweepy or just the twitter REST API to reverse the order of how it retrieves the tweet?

like image 636
Josh Avatar asked Jan 28 '26 03:01

Josh


1 Answers

You can reverse the list and print it out that way

for tweet in reversed(user_tweets):
    print tweet.text
like image 166
Tom Swifty Avatar answered Jan 29 '26 17:01

Tom Swifty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!