Hosting My Own Twitter Bot
2023-04-22
As my “capstone” project for finishing CodingNomads Python 201 course, I decided to create my own Twitter bot. I wanted this project to be at least semi-useful, so I used the free weather API from Visual Weather Crossing to program a bot that tweets a weather update every 6 hours for my city.
(Here is a link to WeatherTonka, the Twitter bot.)
To make this bot I learned and used the following tools:
- Twitter’s Dev Portal and API
- The Python package tweepy
- PuTTY to connect to my Debian server from my laptop
- Linux - Bash scripts, crontab, and rtcwake
I was surprised that the easiest part of this project was writing the Python program for the Twitter bot. After getting my Twitter API access tokens and keys sorted out, I followed the examples in the tweepy documentation and was able to post a tweet within a few hours. (Here is the code.)
Once I had the program working, I started looking into hosting my bot. I checked out Linode and Heroku, but then I decided it might be more fun to host the bot myself. I have this Xi3 Z3RO mini PC I bought a few years ago, and after doing the math on its power consumption, I would pay less than $2.50 a month in energy costs even if it ran 24/7 at full power.
I put a minimal Debian installation on the Xi3. The rest of my time on this project I spent learning how to make crontab and rtcwake work. The end result, I have two cron jobs running. One executes weather_tonka.py every six hours. The second suspends the disk on my little server five minutes after the program is executed and wakes it up again five minutes before the next scheduled run.
Making this simple Twitter bot was a great learning experience. I still have a ways to go in my journey to becoming a programmer, but I am happy and excited to see the progress I’ve made so far. Thanks for reading.
Go Back