Get trending words as a stream with Tweepy - python

What I know:
I have been using Tweepy for a long period and I know how you can create a stream to get new Tweets with a given keyword.
I also know that you can get trending keywords in a specific region from the documentation.
What I am trying to achieve:
I was wondering how I can use the trending APIs to get trending topic but in a form of a stream, so if a topic starts trending in a place, I will like a similar event to the on_data event on the stream listener to get fired and return the new trending topic.
Does anyone know how I can achieve this?
Or any hint on how I can achieve this?

Twitter's API has no streaming endpoint for this, so you'll simply have to poll the GET trends/place endpoint with API.trends_place.

Related

Twitter bot posting to twitter circle

I have a twitter bot that tweets every hour, but I think it would be cool to make it so it tweets from a separate set of tweets or more frequently to a twitter circle, a smaller group of people which I set manually, but I'm not sure if any existing twitter api has that kind of functionality. Is this possible?
I haven't tried anything but I've been scouring the documentation for a while now, I just don't know where to even start in solving this problem.

get tweet when tagged in Tweepy

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

Tweepy not finding results that should be there

I am writing a script in Python, that uses tweepy to search for tweets with a given keyword. Here is the snippet:
for tweet in tweepy.Cursor(api.search, q=keyword, lang="en").items(10):
print tweet.id
I have everything authenticated properly and the code works most of the time. However, when I try to search for some keywords (examples below) it doesn't return anything.
The keywords that cause trouble are "digitalkidz" (a tech conference) and "newtrendbg" (a Bulgarian company). If you do a quick search on Twitter for either of those you will see that there are results. However, tweepy doesn't find anything. Again, it does work for pretty much any other keyword I use.
Do you have any ideas what might be the problem and how to fix it?
Thank you
I believe you're forgetting an important aspect of the twitter api, it's not exhaustive.
Taken from the api docs
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.
Regardless of whether you're using the streaming or rest api, you're going to have issues with this if you're looking for specific tweets.
Rest API
When looking for historical tweets, you unfortunately won't be able to obtain anything that is older than a week using api.search(). This is also shown in the docs.
Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week.
There are other ways of getting older tweets, this post details those options.
Streaming API
While it doesn't sound like you're using twitter's streaming API, it should be noted that this only gives a small sample of twitter's current tweet traffic (~1-2%).
Hopefully this is helpful. Let me know if you have any questions.

Possible to retrieve Twitter topics that were trending on a particular date?

I would like to be able to call a function, in any language (preferably Python :)), where the parameters I pass in are simply a date, or date range, and I get returned a list of the topics that were trending on Twitter (or any other social media) on these dates.
Is it possible to do this? How can I do this if so?
Thank you very much.
It doesn't seem possible through the official 1.1 twitter API, which only provides currently trending topics, but http://twend.it archives trending topics on twitter. You may be able to scrape them or send an email asking if they have an API.

tweepy/twitter get all tweets from a location:

I have the following questions about tweepy python module
1.I am trying to retrieve all tweets for a specific location. I am able to do this by using tweepy python module (streaming API), but I get only those tweets whose geo locations are enabled, which means I would loose rest of the tweeter’s tweet who have not enabled their geo location. Is there a better way to retrieve all the tweets, given a location?
2.I use Stream.Sample method to retrieve all the tweets, Can someone tell me about the parameters used in sample method? I see count, and async as parameters. Now what should we specify here?
3.What does firehose method in tweepy.Stream do?
Any help is much appreciated
If tweepy doesn't have a feature you need, you can always access Twitter directly with an HTTP request. The full Twitter REST API is described here: https://dev.twitter.com/docs/api
The ones that seem relevant to your interest are:
GET trends/:woeid which looks up tweets by woeid, a Yahoo Identifier for collecting information about a given place/landmark/etc.
GET geo/id/:place_id which only mines geotagged tweets.
There is documentation of all the information available for a GET request but the IP address is not among the available fields: https://dev.twitter.com/docs/api/1/get/search .
Lastly, Twitter has a location search FAQ that may be of interest.

Categories