cordmana
cordmana

Reputation: 151

Collect tweets from multiple users at the same time with tweepy

Currently I am working on a project with tweepy to collect new tweets from users very quickly. So far, I have found that the fastest method to collect the newest tweet of a user is like so:

tweets = api.user_timeline(screen_name='user',count=1, include_rts = True,tweet_mode = 'extended')

status = tweets[0]

I was wondering if there is anyway to get the most recent tweets of multiple users in one request? I tried using a streamer, but that ended up having about a 10 second delay between when a tweet was posted and when it popped up, which is way too slow for my application. Please let me know if you have any other ideas on how to fetch tweets quickly.

Thanks

Upvotes: 0

Views: 683

Answers (1)

William O'Connor
William O'Connor

Reputation: 41

I haven't used tweepy to search the posts by user, but I have used it to extract information on multiple hashtags before.

When I tried with multiple hashtags the code looked like this:

query = "(#nike OR #puma OR #adidas)"
rule = gen_rule_payload(query, results_per_call=100, from_date="2020-11-30", to_date="2020-12-02")

So I would try for you query:

users = "(User1 OR User2 OR User3)"
tweets = api.user_timeline(screen_name=users,count=1, include_rts = True,tweet_mode = 'extended')

status = tweets[0]

I'm not sure if that will work, but fingers crossed! The good thing about working with Twitter is that you can copy paste your search strings directly into the search box on a normal twitter webpage and see if your syntax is correct.

Upvotes: 1

Related Questions