DEV Community

How to Set up a Twitter Bot with Python and Heroku

Emily Cain on June 24, 2018

I just set up a Twitter bot to generate pharmaceutical ads and tweet them out a few times a day. (Source code here). I ended up piecing together co...
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
emcain profile image
Emily Cain

Can you elaborate? What step are you on? What have you done so far?

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
emcain profile image
Emily Cain

The code on my GitHub is the most recent version.

What happens when you try to run it in the command line (commenting out the env variable loading and uncommenting the import from constants)?

Collapse
 
wolverine2k profile image
Naresh Mehta

Heroku plus uptime or cronjob can help you automate the bot. My bot is up and running @ twitter.com/perfmetrics_bot. My blog post below has more details.

naresh.se/2017/09/19/automate-twit...

Collapse
 
narayanbhat166 profile image
Narayanbhat166

Hey my python worker just crashes everytime i try to run it
i get "state changed from starting to crashed"
and returns status code 0
but in my program i send a telegram message, i dont receive any message

Collapse
 
zogzmiller profile image
zogzmiller

I recently tried following this article to set up a twitter bot that replies with sentiment analysis of whatever user the person requests. Currently the bot works and runs through terminal but is not doing anything once deployed in heroku. If someone is willing to take a look at what I have so far and give feedback would be greatly appreciated. The github link below has my heroku bot folder

github.com/zogzmiller/heroku-bot.git

Collapse
 
jordytrevor profile image
Trevor Jordy

Hi, I just followed your guide and pushed everything successfully, but nothing is happening. How can I tell if my bot is running properly? I have print() statements that I should be seeing in the logs. The bot builds correctly its just nothing happens. Does it run automatically, or do I have to do something to run it?

Collapse
 
emcain profile image
Emily Cain

I just saw this...do you have a Twitter account hooked up to it? Is it publishing tweets?

Collapse
 
cokastefan profile image
Stefan Petrushevski

You can also use heroku scheduler without setting up a web app. Just set it up to run python boty.py at your desired interval.
devcenter.heroku.com/articles/sche...

Collapse
 
alialhajji profile image
Ali Alhajji

Good job. I've been looking for such a solution to run my code other than my local machine. Thnx Emily!

Collapse
 
willemm6 profile image
willemm

Nicely done!

Collapse
 
meronzonzo profile image
👽

Good post! I did the same for a bot I just rewrote (@linuxsecbot). I was about to setup flask when I saw that Heroku supports scheduled tasks. With python is done with APScheduler. Thanks for posting!

Collapse
 
sheenbanach profile image
sheenbanach

wow this is an awesome post thanks

Collapse
 
aakash profile image
Aakash Deep

great post! thanks.
I've a question though, how do I see the logs from the python script? executing 'heroku logs' gives me the logs related to the web server.