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
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.
Related
I am using python package GetOldTweets3 to extract all tweets from a specific user between a specific timeframe. However, I only want the 'original' tweets, and no public replies or retweets the user makes.
Is there any possibility to do this with GetOldTweets3 or any way to expand the package?
import GetOldTweets3 as got
tweetCriteria =
got.manager.TweetCriteria().setUsername(username).setSince(startdate).setUntil(enddate)
tweets = got.manager.TweetManager.getTweets(tweetCriteria)
I've been using GetOldTweets3 recently and I don't think that you'll get user retweets from the result. For the replies, you can just get the reply for each record by adding tweet.to to your result and choose the record that has null for that.
I am using tweepy with python (flask) for a small project. I want to fetch users against a query from twitter. Currently I am using cursor object and it returns me tweets. But I want to fetch users instead of tweets.
I think what I am getting right now via cursor is the top results so I want the results in People tab instead of Top tab.
Any idea how should I do that?
Screenshot is attached for what I want!
https://i.stack.imgur.com/0zGUm.png
I found this in tweepy documentation.
After basic twitter auth:
twitterAuth = twitterClient()
api = twitterAuth.get_twitter_client_api()
api.search_users(q, 20, 1)
Here q is your search term, 20 is the number of results per page (max 20 allowed) and 1 indicates the page number from where you want to collect the users. For example if you want to fetch users from 1st page it will be 1 else any other page number.
Hope this helps everyone!
noofitem = 1000
tweets = tweepy.Cursor(api.search,q=['#iphone11, -filter:retweets'],since='2019-11-14',lang='en',tweet_mode='extended',retweeted=False).items(noofitem)
i = [tweet.full_text for tweet in tweets] #Tweet text
I am trying to get about 1000 tweets using tweepy. But the max tweets I get are around 600. Changing the date does not work. Any modification or other workarounds will be helpful. Thanks.
Please note that Twitter’s search service and, by extension, the
Search API is not meant to be an exhaustive source of Tweets. Not all
Tweets will be indexed or made available via the search interface.
Please refer to this link for more information: http://docs.tweepy.org/en/latest/api.html#help-methods
Probably you will need to set up a Stream to get the amount of data you need.
I'm working on an automatic text to speach generator using tweep and gTTS.
And what I'd like to is whenever a user tags my bot, my bot will reply with a generated TTS response of their tweet.
Example if Malcolm tweets "#bot Banana Bread" well the bot will reply to that tweet with a mp4 file of a voice saying "banana bread"
I think I could pull of the TTS generation with gTTS and some messing around.
However I don't know how I could automatically get the tweet Id and so the tweets text when I'm tagged.
The only method I see is to constantly refresh a
example = tweepy.Cursor(api.search, q='#bot').items(1)
and then
for tweet in example:
print tweet.text, tweet.id_str
and then store the id so that it only gets the latest posts and doesn't reply to the same tweet twice.
But this seems like a bit much, and I'm wondering if there's any faster/easier/more efficient way of doing this?
Your method is good : store tweet IDs you answered to, and check them before a new reply. With time, it can be a lot of IDs so you have to handle delete of very old ones.
Another way is to use the Twitter Account Activity API : via a webhook (an URL of your personnal web server), you can get mention events, then simply reply directly.
If i understand the official documentation, 1 free webhook is available with premium API.
Here is documentation :
https://developer.twitter.com/en/use-cases/engage#chatbots-and-automation
https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/overview
I want to track all tweets of a particular hashtag but i need only the tweets with geolocation.
This line not working fine, the results are all tweets with geolocation.
stream.filter(track=["hashtag"],locations = GEOBOX_WORLD)
This work fine.
stream.filter(track=["hashtag"])
This work fine.
stream.filter(locations = GEOBOX_WORLD)
But the union of track and location don't work. There is some solution (without check tweet by tweet if .geo != None)?
Thanks.
You can't filter both things at once, you need to choose one and then check the other.
Here you can find a more detailed answer to a similar question: How to add a location filter to tweepy module