A Python bot that looks up new posts from a subreddit and automatically posts them on Twitter.
With an understanding of Python, and some brief understanding of PRAW and tweepy, you should be able to edit it with ease. By default:
- The script is ran every hour (3600 seconds), assuming it is still online.
- It cannot be ran as-is - you need to edit in the subreddit you wish to follow, and the Twitter/Reddit ID's/secrets.
- You'll need to create a txt file for caching results (name it
posted_cache.txt
- make sure you edit the code if you name it something different). - Default delay between tweets is 30 seconds.
- By default, the script looks up the last 10 NEW posts. It the checks if it's tweeted them already or not - if not, it'll tweet them.
All this can be edited if you wish.
I hold no liability for what you do with this script or what happens to you by using this script. Abusing this script can get you banned from Twitter, so make sure to read up on proper usage of the Twitter API.
You will need to install Python's tweepy and PRAW libraries first. I personally recommend using poetry do manage this, but you can install them via pip
if you please.
You will also need to create an app account on Twitter: [instructions]
- Sign in with your Twitter account
- Create a new app account
- Modify the settings for that app account to allow read & write
- Generate a new OAuth token with those permissions
- Manually edit this script and put those tokens in the script . (note - by default your app will have Essential perms. With these perms, you must use the client class within tweepy (TWITTER API V2 REFERENCE))
And a Reddit account:
- Go to https://www.reddit.com/
- Click
Sign Up
(top right on desktop) and fill out the necessary items. - Once logged in, you may wish to verify your email.
- Go to the apps page https://old.reddit.com/prefs/apps/
- Click
Create another app...
at the bottom. Fill out relevant details. - Your app
client_id
is located under the app name, e.g "-x1_KIHUOOJmk". The secret is below this as well.
Once you edit the bot script to provide the necessary API keys and the subreddit you want to tweet from, you can run the bot on the command line:
python reddit_twitter_bot.py
Or if you use poetry:
poetry run python reddit_twitter_bot.py
Look into the script itself for configuration options of the bot.
If you're having issues with or have questions about the bot, please file an issue in this repository so one of the project managers can get back to you. Please check the existing (and closed) issues to make sure your issue hasn't already been addressed.