The Georgia Tech Library's retroTECH lab specializes in collecting vintage technologies. One collecting area has been vintage video game consoles. This Twitter bot tweets weekly an image of a game from this collection with a link to a playable emulated version from the Internet Archive's Console Living Room.
The bot composes its tweets using the data provided by data.json:
- The bot requests the image provided by
data.tweets[0].smartechUrland downloads the image locally in./images/image.png. - It then compiles a tweet with all the info from
data.tweets[0]. - After tweet is sent,
data.tweets[0]is deleted. This movesdata.tweets[1]up and removes the need from having to loop through the data.dataMain.jsonis left untouched so there is a record to use if the bot crashes. ./images/image.pngis also deleted.- The bot then waits a specified amount of time before tweeting again using node-cron.
git clone https://github.com/PoorBillyPilgrim/gtlibrary-retrotech-twitterbot.git- Twitter's API requires API secrets and tokens created in a Twitter developer account. Store yours in an
.envfile in the project directory. - Install dependencies:
cd gtlibrary-retrotech-twitterbotthen runnpm installoryarn install. - Start bot:
node index
Instead of simply running node index, you can use process managers to restart your bot on a server reboot. I have used pm2 and systemd service units. I self host two projects on Ubuntu servers and have had luck using Ubuntu's service units. A very simple example:
- Create service unit:
sudo nano /etc/systemd/system/twitterbot.service
[Unit]
Description=retroTECH Twitter bot
[Service]
WorkingDirectory=/home/gtlibrary-retrotech-twitterbot
# ExecStart starts project (it's relative to WorkingDirectory)
ExecStart=/usr/bin/node index.js
# if process crashes, it will always try to restart
Restart=always
[Install]
WantedBy=multi-user.target
- Run service:
sudo systemctl daemon-reloadsudo systemctl enable twitterbotsudo systemctl start twitterbot
- Check that it is running:
sudo systemctl status twitterbot
An excellent article found in code4lib Issue 48 by Meredith Hale of the University of Tennessee spurred me to create a Twitter Bot.
Scott Carlson at Arizona State University was an immense help and resource.
MIT License © Tyler Jones