A reddit bot built using Selenium and PRAW for the subreddit of the film-discussion podcast Sardonicast. The bot responds with film ratings from the 3 hosts Adam, Ralph and Alex when users ask. You can head on over to u/sardsbot to see the bot's latest activity.
You will need:
- A Letterboxd account for the bot. For this to work, be sure to follow only the accounts of Adam, Ralph and Alex on this account.
- A reddit account for the bot. Create an application using said account to obtain a
CLIENT_IDandCLIENT_SECRET.
- Clone this repo and install dependencies with
pip install -r requirements.txt - Fill out your crendentials in
config.json. The config file should look like this:
{
"letterboxd_username": "letterboxd_bot",
"letterboxd_password": "password",
"reddit_client_id": "CLIENT_ID",
"reddit_client_secret": "CLIENT_SECRET",
"reddit_username": "reddit_bot",
"reddit_password": "password",
"user_agent": "bot by u/user",
"subreddit": "Sardonicast"
}
- Install ChromeDriver and Google Chrome. If you run this locally and have Chrome installed, you should comment out the line
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")inmain.py. - Include the ChromeDriver location in your PATH environement variable. If you do this, you should not pass in
executable_path=os.environ.get("CHROMEDRIVER_PATH")when callingdriver = webdriver.Chrome(options=chrome_options)inmain.py. Otherwise, you can set your ChromeDriver location to theCHROMEDRIVER_PATHenvironment variable. - If you want to test the bot, you can set the
subredditfield inconfig.jsonto a subreddit like r/testingground4bots. - Run
python main.py
I'm hosting the bot using Heroku. If you are deploying in another way, make sure you can install ChromeDriver and Google Chrome or add the location of ChromeDriver and the Google Chrome binaries in your environment variables.
To deploy using Heroku, you need to add the following buildpacks to your app in addition to the standard python buildpack:
Simply copy and paste in the urls of the github repositories.
Set the following additional config vars in you app settings:
KEY: CROMEDRIVER_PATH,VALUE: /app/.chromedriver/bin/chromedriverKEY: GOOGLE_CHROME_BIN,VALUE: /app/.apt/usr/bin/google-chrome
Create a Procfile and include the single process worker: python main.py.
Finally, deploy via git push heroku master.
The bot uses Selenium to login to a Letterboxd account that follows the 3 hosts of the podcast. It then scrapes their ratings, watchlist information and reviews for a given film. It also scrapes the Letterboxd search results to make it easier for users (when a redditor comments !ratings <film_title>, the bot scrapes the Letterboxd search results for <film_title> for the best match).
The Letterboxd API is currently in closed beta, and it is unclear how easy it is to gain access. If I eventually get access, I will make sure to rewrite the bot to use the API instead. Until then, this is the best implementation I came up with.
