Automating BCBCBath Website

Cooking Up a Website with Python, Spreadsheets, and APIs

In 2022, Sahil and I started BCBCBath, a cookbook club in Bangalore, as a way to connect with fellow food lovers and explore diverse cuisines. Each month, members vote on a cookbook, cook a dish from it at home, and gather for a themed potluck. Initially, I was updating the menu manually with Obsidian to publish it online. As the club grew, manually updating the website became time-consuming, so I decided to automate the process using Python.

Here’s how the automation works:

  1. BCBCBath members track potluck details like date, cookbook title, attendees, and dishes in a Google Spreadsheet. Each potluck gets its own sheet.
  2. The Python script uses the requests library to fetch the spreadsheet data as CSV. It parses the CSV data using the csv module and extracts relevant information for each potluck.
  3. To get additional cookbook details, the script utilizes the amazon_paapi library to interact with the Amazon Product Advertising API. It fetches the cover image, author name, and purchase link for each cookbook.
  4. The extracted data is used to create instances of a custom PotluckMetadata class, which serves as a structured representation of each potluck’s information.
  5. The script then generates an HTML page for each potluck using the Jinja templating engine. It passes the PotluckMetadata instances to predefined Jinja templates, which render the content into HTML.
  6. To create paginated index pages, the script divides the potlucks into chunks based on a configurable potlucks_per_page value. It generates an index page for each chunk, displaying a grid of potluck cards with cover images and dates.
  7. The generated HTML files are written to the website directory
  8. The script logs its progress and any errors using the logging module, making it easier to diagnose issues.
  9. Configuration variables like API credentials, output paths, and website metadata are stored in a separate config.py file, promoting code reusability and maintainability.
  10. A main() function orchestrates the entire process, handling the flow of data retrieval, HTML generation, and error handling.

With this automated setup, updating the BCBCBath website is as simple as having members edit the spreadsheet and running the Python script. The script fetches the latest data, generates fresh HTML pages, and updates the website in minutes.

Building this automation script was a great opportunity to leverage Python’s rich ecosystem and practice working with libraries like requests, csv, jinja2, and amazon_paapi.

I’m sure there are better ways to execute this. Happy to chat @unitechy