A simple framework for Twitter bots creating memes from Stack Exchange questions.
Take questions posted on a particular Stack Exchange site, generate a meme out of them and tweet them.
Uses the following APIs:
- Stack Exchange
- Twitter (via Twython)
- imgflip
- @pi_stack (Raspberry Pi)
- @overflow_meme (Stack Overflow)
- @worldbuildingme (World Building)
- @askubuntumemes (Ask Ubuntu)
- @stackamemia (Academia)
You can run your own instance of a Twitter bot following a particular Stack Exchange site. You need to register for API keys for the relevant services.
-
Sign up for a Twitter account, create an app and get your four API keys.
-
Sign up for an imgflip account and note your username and password.
-
Register for a Stack Exchange App Key and find your user ID for each site (click on your avatar to go to your user page and your ID is the number in the URL e.g.
806889
in stackoverflow.com/users/806889/ben-nuttall) - note these are different for each site.
-
Install this project:
sudo pip3 install memeoverflow
-
Copy the example script
example.py
(e.g. toraspberrypi.py
) and edit your copy to specify:- the Stack Exchange site you wish to follow (get the exact string here) and your Stack Exchange API key
- your Twitter account's API keys
- your imgflip's username and password
- the path to your meme database file (can be a non-existent file, as long as the file location can be written to)
- Optionally, the path to your log file (can be a non-existent file, as long as the file location can be written to)
If you want to log to a file, populate the logfile
function call as provided
in the example.py
script.
If the path to the provided log file is writeable by your user, you are ready to
go. Here's an example of what you need to write logs to
/var/log/memeoverflow/
:
-
Create the directory and chown it:
sudo mkdir /var/log/memeoverflow sudo chown ben: /var/log/memeoverflow
-
Set the logfile to e.g.
/var/log/memeoverflow/raspberrypi.log
inraspberrypi.py
- Run it directly:
python3 raspberrypi.py
Log entries will be written to stdout (and optionally to a log file if
specified). You'll have to keep the process active to keep it running, unless
you background it with &
. Alternatively, use systemd.
Alternatively, use systemd:
-
Copy the example systemd service
memeoverflow-example.service
into/etc/systemd/system/
:sudo cp memeoverflow example.service /etc/systemd/system/memeoverflow-raspberrypi.service
-
Edit the service (edit
Description
and path to file inExecStart
):sudo vim /etc/systemd/system/memeoverflow-raspberrypi.service
-
Reload systemctl daemon:
sudo systemctl daemon-reload
-
Enable and start the service:
sudo systemctl enable memeoverflow-raspberrypi.service sudo systemctl start memeoverflow-raspberrypi.service
-
Check the status:
sudo systemctl status memeoverflow-raspberrypi.service
If a log file is specified, log entries will be written there. They will also be
visible in systemctl status
which gives real evidence of it running correctly.