- Copy top post of the day from a Subreddit to a Twitter account (I will never call it X!).
I'm using Ubuntu LTS on an Oracle Cloud VM. There are free-tiers available as of today. Google Compute and Amazon AWS are similar products. You can also roll your own host with an old PC or a Raspberry Pi. You'll need to know a bit of Linux CLI or you'll need to be ready to learn! Run these commands through the CLI.
-
Go here and install Git if you don’t have it already.
-
Assuming you're reading this on the repo page, select ‘fork’ to create a copy of it to your Github account.
-
From your new repo, select Code and then under Clone copy the HTTPS URL (e.g. https://github.com/SaltySOMAdmin/Reddit-To-Twitter.git) to download a local copy
-
Navigate to a folder you want a local copy of the repo to live, and clone the Github repo to your host:
- It's up to you where to put the repo - recommended in a folder like /home/YourUserAcct/Github/ or /home/YourUserAcct/. Once you clone the directory it will create a subfolder with the name of your fork.
- git clone
<url>
- e.g. git clone https://github.com/SaltySOMAdmin/Reddit-To-Twitter.git
-
Install Python3
sudo apt install python3
-
Create a python virtual environment in a directory
/usr/bin/python3 -m venv /home/ubuntu/Reddit-To-Twitter/
-
Use the virtual python3 environment
source /home/ubuntu/Reddit-To-Twitter/bin/activate
-
Install Twitter SDK and other pre-reqs
pip install tweepy pip install praw
-
Create a file called config.py and save it in the same directory as your script. Enter Reddit and Twitter api credentials. Check out the example file for formatting.
-
Configure forward_log.sh with a Discord webhook if you want logs forwarded. Enter the webhook in a .txt in the same directory or directly into the code.
-
Setup a schedule to run
crontab -e #Twitter Post daily at noon 0 17 * * * /bin/bash -c "source /home/ubuntu/Reddit-To-Twitter/bin/activate && python3 /home/ubuntu/Reddit-To-Twitter/topPostDay.py" >> /home/ubuntu/Reddit-To-Twitter/twitter_log.txt 2>&1 #upload Twitter logs to Discord 5 17 * * * /home/ubuntu/Reddit-To-Twitter/forward_log.sh
Allows you to deploy your code via Github vs logging into the VPS and updating the code/uploading a new file. Allows for easier collaboration as well. I followed a guide similar to this one: https://docs.github.com/en/actions/use-cases-and-examples/deploying/deploying-with-github-actions