Generate EPUB documents from RSS feeds and URLs and take your e-book reader offline

Σεπ 10 2023

I like e-book readers. In a couple of minutes, you can get the books you like and get started with reading them. Or RSS feeds and that random article you have marked as "read-it-later". The reading experience is nice. Thanks to the e-ink technology, eye strain is drastically reduced. You can also set font type, size, line spacing and margins as you wish. Great.

I don't like e-book readers. I trust devices that run maintained, free software. Most e-book devices run on custom, unmaintained Linux kernels. Others, depend on proprietary software. I don't trust e-book reader devices. And their cost is not insignificant. Not great.

So, I took my humble e-book reader offline. It communicates with the external world with an SD card.

And I created a simple terminal utility which I run on a trusted device. It does this:

  • Mounts an SD card
  • Fetches RSS feeds
  • Downloads read-it-later articles
  • Converts them to e-pub documents
  • Saves them to the SD card
  • Unmounts the SD card

Instead of an SD card, it can also save the e-pub documents to a local ~/path/to directory.

The utility can be found on Codeberg. It is written in Python, it makes use of Calibre for the RSS part and python-readability for the articles.

RSS feeds should be created as Calibre recipes. The configuration of the recipes can be found at ~/.config/calibre/custom_recipes or, if Calibre has been installed as flatpak, at ~/.var/app/com.calibre_ebook.calibre/config/calibre/custom_recipes.

The read-it-later links should be added to a plain text file, e.g. ~/Documents/read-it-later.txt, like this:

www.example.com/my_article.html
Another article www.example.com/another_article
Yet another [article](www.example.com/yet_another.html)

You are going to need the uuid of your SD card. Run ls -l /dev/disk/by-uuid/. Then, plug the SD card into your computer. Run ls -l /dev/disk/by-uuid/ again. The new line contains the uiid of the SD card.

A couple of directories are need as well: - the directory that the SD card should be mounted to, e.g. /mnt/jane/sd. - the target directory for the e-pub documents. It should be a relative path on the SD card, e.g., newspaper/news.

To install the Python dependencies, run pip install -r requirements.txt. A virtual environment is a good idea.

Finally, run:

python ebook_newspaper.py --recipes_dir ~/.config/calibre/custom_recipes --target_device /dev/disk/by-uuid/7afb-3231 --target_mount_point /mnt/jane/sd --target_dir newspaper/news --read_it_later_urls ~/Documents/read-it-later.txt

or, if you don't need an SD card:

python ebook_newspaper.py --recipes_dir ~/.config/calibre/custom_recipes --home_target_dir ~/Documents/newspaper --read_it_later_urls ~/Documents/read-it-later.txt

If Calibre has been installed as flatpak, add the --flatpak option:

python ebook_newspaper.py --flatpak --recipes_dir ~/.var/app/com.calibre_ebook.calibre/config/calibre/custom_recipes --target_device /dev/disk/by-uuid/7afb-3231 --target_mount_point /mnt/jane/sd --target_dir newspaper/news --read_it_later_urls ~/Documents/read-it-later.txt

To archive the older e-pub documents on each script execution, set the --archive option:

python ebook_newspaper.py --archive --recipes_dir ~/.var/app/com.calibre_ebook.calibre/config/calibre/custom_recipes --target_device /dev/disk/by-uuid/7afb-3231 --target_mount_point /mnt/jane/sd --target_dir newspaper/news --read_it_later_urls ~/Documents/read-it-later.txt

Happy reading.