Skip to content

mattjliu/Sardsbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sardsbot

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.

Setup and Installation

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_ID and CLIENT_SECRET.
  1. Clone this repo and install dependencies with pip install -r requirements.txt
  2. 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"
}
  1. 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") in main.py.
  2. 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 calling driver = webdriver.Chrome(options=chrome_options) in main.py. Otherwise, you can set your ChromeDriver location to the CHROMEDRIVER_PATH environment variable.
  3. If you want to test the bot, you can set the subreddit field in config.json to a subreddit like r/testingground4bots.
  4. Run python main.py

Deployment

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/chromedriver
  • KEY: 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.

Letterboxd API

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.

Releases

Packages

Contributors

Languages