A Reddit bot for selecting a random song each week and then posting it on the given Subreddit. SOTW-bot has options to post to multiple Subreddits or manage multiple Subreddits with a single instance.
Used By:
- r/KidCudi
- Feel free to add your subreddit to the list!
- A Linux Instance (with an internet connection)
- Python 2 (Tested on Python 2.7), (Python 3 support coming soon...)
Start by cloning this repo and its dependencies. Open Terminal, navigate to where you want to place the bot, and run these commands:
git clone https://github.com/jakeehall/SOTW-bot.git
pip install praw
Settings_Template.py is where the bots information is stored. Fill out the file with the correct information, save it, and rename it to Settings.py
You will need the following information:
client_id = '' # Generated by Reddit, See Below!
client_secret = '' # Generated by Reddit, See Below!
username = '' # Bot Username
password = '' # Bot Password
subreddit = '' # Subreddit (don't include the /r/prefix, just "prefix")
flairCSS = '' # For Old Reddit, name of CSS class, if used
database = '' # Any name that matches your SQLite DB file
historyEnabled = True # [OPTIONAL] Selections will not be saved to database
postingEnabled = True # [OPTIONAL] Selections will not be posted to Reddit
- If historyEnabled is set to False, songs aren't added to the History table in the database, this also causes duplicates of selected songs as a side-effect.
- Create and log into your SOTW account. (DO NOT USE YOUR PERSONAL REDDIT ACCOUNT)
- The SOTW bot account must be a moderator on the given Subreddit
- SOTW will always be the first sticky on the given Subreddit
- Go to https://www.reddit.com/prefs/apps, scroll to the bottom of the page and click the "create another app..." button.
- Choose whatever name you like, select the "script" radio button, choose a fitting description, in the about URL put a link to this GitHub page, and for the Redirect URI put "http://localhost", and finally click the "create app" button.
- You will now see a new new item with the name you chose under "developed applications". Click the "edit" link to see more information.
- Look for the client_id and client_secret information as illustrated below.
"database_template.db" is also provided as a template database that can be used and renamed to "database.db" for actual use. The template has the first row of fields filled as an example, so be sure change that rows values before use. To get the bot fully up and running open the database in SQLite Browser and add all of the songs you wish to select from into the Song_Index table.
Note 2: The History table can be left blank as it will automatically be generated as songs are selected.
Crontab comes with Linux and allows the scheduling of tasks for automation. This is what runs the SOTW-bot script every week, once a week.
In schedule.cron you will see the following format:
0 18 * * 5 cd /home/USER && /usr/bin/python /home/USER/SOTW-bot
This means the bot posts every week on Friday (5) at 6pm (18).
IMPORTANT: The posting time is relative to the time zone set on the server where the script is running. For example, if your servers time is set to Eastern Time US (GMT-4) then the script will post at 6pm Eastern Time, but if the server time is set to Pacific Time US (GMT-7) then the script will post at 6pm Pacific Time US.
ALSO: Change "USER" to the username on your Linux server, you should NOT be executing this script as root.
You're welcome to change the cron job to whatever time you prefer, but I've found that this time works well for getting the most visibility in the US. There's plenty of resources and generators for crontab so I won't explain how to use it here. Just remember if you do modify the time, make sure you keep the tail of the command the same "cd /home/USER && /usr/bin/python /home/USER/SOTW-bot".
After Crontab is configured run the following command:
crontab schedule.cron
Versions 1.3.0 and higher support posting to multiple Subreddits or running the script with test Settings.
Before updating SOTW-bot, check the GitHub page for and read if changes need to be made to your database, arguments, crontab, etc... After confirming that you're ready to update run the command:
git fetch && git pull