Go to file
notplants fc5eaff0e7 list 2024-02-21 12:58:57 -06:00
templates templates 2024-02-21 12:32:38 -06:00
.gitignore templates 2024-02-21 12:32:38 -06:00
README.md list 2024-02-21 12:58:57 -06:00
example.yaml example.yaml 2024-01-26 22:07:24 -06:00
main.py cleanup 2024-02-21 12:49:11 -06:00
run.sh templates 2024-02-21 12:32:38 -06:00

README.md

bookshelf-generator

This is a python script for two tasks:

  1. downloading the contents of a bookwyrm list into a yaml file, along with a directory containing all the cover images for the listed books
  2. using the yaml file and image directory from the previous step to generate a static HTML file using a jinja template file of your choice

Here is an example, of using the both parts of the script, with the list https://bookwyrm.social/list/2634/s/calvin-and-hobbes

# download the bookwyrm list at https://bookwyrm.social/list/2634/s/calvin-and-hobbes and save the contents into a yaml as well as all the cover images into a folder at calvin-and-hobbes
python3 main.py bookwyrm-download --list-url="https://bookwyrm.social/list/2634/s/calvin-and-hobbes" --output-dir="calvin-and-hobbes"
# from the yaml and directory of images downloaded in the previous step, generate a static html page using the template in templates/bookshelf.html
python3 main.py generate-html --yaml-path="calvin-and-hobbes/books.yaml" --images-dir="calvin-and-hobbes" --template="templates/calvin-and-hobbes.html" --output-path="output/calvin-and-hobbes"

I used required named arguments for this script, for clarity of what arguments were being passed.

I divided the script into two subcommands, bookwyrm-download and generate-html, so that they could potentially be used independently.

If in the future the bookwyrm schema changes and I don't feel like updating the script, I can switch to just manually editing yaml files and creating image directories, and continue using the generate-html script.

Example template files are in the templates folder and are made using jinja. You can modify these or make your own.

https://books.commoninternet.net is an example website generated with this script from three bookwyrm lists.


ActivityPub

Bookwyrm is built using ActivityPub which I wanted to explore a bit with this script.

I was able to easily download the contents of a list into a yaml using the json+ld endpoint for the URL of the list.

For example, in bash, for the same calvin and hobbes list:

http https://bookwyrm.social/list/2634/s/calvin-and-hobbes?page=1 "accept: application/ld+json"

Thus its very easy to fetch various objects from Bookwyrm and transform them or use them in a new context.

Bookwyrm documentation on ActivityPub: https://docs.joinbookwyrm.com/activitypub.html