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
Related
I'm working on a bot that does jobs for Twitter users. They're supposed to request help by mentioning my bot like "#bot" with any other options in the text, optional.
Problem is, Twitter seems to consider directly #'ing someone in a new standalone tweet like "#jake hey" and replying to a tweet that user #jake made, with "hey" to be the exact same thing. If I check the full_text field for each status on tweepy, they both appear as "#jake hey". My bot needs a user supplied video to do its job. So if my bot were to reply to someone with a finished job, someone could reply to my bot with a video as a reaction to it, perhaps a video where someone says "Thank you!", my bot would confuse that as someone trying to request it to analyze that video for it. I need to prevent this so I don't reply to that user who didn't actually want to submit the video to my bot. I can't seem to find a way to differentiate between these two tweet examples, they seem to be the same under the hood. I hope I explained it soundly enough. Any ideas what I can do?
I was wondering if it is possible to "quote a tweet" through direct messages using TweePy. I know this can be done regularly in the Twitter app using the share feature but I was wondering if this could also be possible through Python.
Tweepy recommends that you send the URL of the tweet in a direct-message. https://github.com/tweepy/tweepy/issues/859
The URL will generate a formatted preview in the recipients inbox.
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.
Suppose that a twitter user has sent a tweet which has a specific tweet id. What is the best way to get n tweets from same user exactly before that specific tweet id using tweepy?
Any help will be appreciated.
Read the official Twitter documentation :
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
And use the parameter q with from:#user and count=10 where 10 is your "n" andmax_id=id where "id" is your tweet id.
And read the officiel tweepy documentation for the seach API.
We can fix bugs for you but won't code for you.
I'm writing a simple Twitter bot in Python and was wondering if anybody could answer and explain the question for me.
I'm able to make Tweets, but I haven't had the bot retweet anyone yet. I'm afraid of tweeting a user's tweet multiple times. I plan to have my bot just run based on Windows Scheduled Tasks, so when the script is run (for example) the 3rd time, how do I get it so the script/bot doesn't retweet a tweet again?
To clarify my question:
Say that someone tweeted at 5:59pm "#computer". Now my twitter bot is supposed to retweet anything containing #computer. Say that when the bot runs at 6:03pm it finds that tweet and retweets it. But then when the bot runs again at 6:09pm it retweets that same tweet again. How do I make sure that it doesn't retweet duplicates?
Should I create a separate text file and add in the IDs of the tweets and read through them every time the bot runs? I haven't been able to find any answers regarding this and don't know an efficient way of checking.
You should store somewhere the timestamp of the latest tweet processed, that way you won't go throught the same tweets twice, hence not retweeting a tweet twice.
This should also make tweet processing faster (because you only process each tweet once).
I wrote a twitter bot in python a few months ago and this link helped a lot. I also used this github repo which although is in Ruby, was quite helpful for logic flow. This repo uses a similar approach to what you mentioned, creating a local datastore of previous retweets to compare against each tweet.
This is how I did it. I grabbed the list of things to retweet and a list of my feed. I cut the lists down to only posts within the past 24 hours. Then for each item in retweetable I check to see if it's in my feed list. If not I post RT #user retweet content.
I also wrote a function to chop the str down to 140 chars (137 + '...')
E.G.
TO_RT = 'a post to post'
MYTWT = ('old post', 'other old post')
if TO_RT not in MYTWT
Tweet(TO_RT)
Twitter is set such that you can't retweet the same thing more than once. So if your bot gets such a tweet, it will be redirected to an Error 403 page by the API. You can test this policy by reducing the time between each run by the script to about a minute; this will generate the Error 403 link as the current feed of tweets remains unchanged.