Make library card catalogue PDFs with Python scripts

From Parallel Library Services
Revision as of 17:48, 20 October 2021 by Simon (talk | contribs)
Jump to navigation Jump to search

This recipe depends on the installation of

  • a python virtual environment
  • a cloned git repository
  • calibrestekje, a python-bindings library
  • a metadata.db file as produced by an existing installation of Calibre

If you don't have calibre installed yet, you should do this before trying out this recipe. The contents that are produced in the PDF depend entirely on what is in the metadata.db file. Alternatively, it may also be useful to install calibre and force it to make an empty, but valid metadata.db file. This file can be written to using calibredb, a tool that comes with the calibre package.

Getting started

First, clone the git and change to the new bootleg/ directory:

git clone https://git.xpub.nl/simoon/bootleg.git
cd bootleg/

In the bootleg/ directory, create and activate a python virtual environment. Once activated, you'll notice the prompt in the terminal has changed to be prefaced by (venv), which indicates that the virtual environment is active.

python3 -m venv venv
source venv/bin/activate

Then, install dependencies in the python environment.

pip install reportlab 
pip install calibrestekje
pip install pillow

Make sure you have a valid metadata.db file in the same bootleg/ directory. One which is usually produced the first time you run Calibre in a path similar to /home/myusername/calibre/metadata.db on Debian and Unix-like systems. This file is usually kept with the contents of the Calibre book collection.

Next, run this command:

python3 reportlab_image_poster.py

This will produce a PDF, and also a list of the contents. In my case, it produced a 1048 page PDF in seconds, with the title and author of each book on separate pages of a card catalogue.