Calibre Recipes—News on your Kindle

The news icon from calibre

Calibre, a free and open source program for working with ebooks and ereaders, has some interesting capabilities when you poke around. One of these is the big red “Fetch News” button and dropdown.

Don’t ask me how I first found it—it was a while ago now, and anyway it is rather big and red. When you open ‘Schedule News Download’ in the dropdown menu you get a whole list of languages and places (e.g. “English,” “English (Ireland),” and “Irish”) and associated pre-built recipes, and selecting one and clicking “download now” begins what is potentially a rather protracted process of downloading and processing the RSS feeds into an ebook—albeit a rather special one.

An article in the calibre reader
An article from the io9 feed in the Calibre reader.

It doesn’t look like much in Calibre’s own viewer, but if sent—via email or over usb, both of which Calibre can help you with—to a kindle (and perhaps other ereaders) it creates a display of feeds and articles that can be leisurely browsed through.

But if you instead choose to add a custom news source you get the option to add your own feeds, building the magazine or newspaper you want to read in the morning. Further, options to schedule downloads mean that at specified times (provided your computer and Calibre are running) the feeds will be downloaded automatically.

You can see why this might be interesting, I hope.

Of course, that’s a big caveat—if you had to leave your computer on all night running Calibre so that it could prepare your news for the morning it would be a tad inconvenient. Luckily, if—big if, I know—you happen to have a server lying around (which is to say, a computer that is left on all night but is generally not on your desk in your bedroom lighting the whole room up while you’re trying to sleep) Calibre provides command-line tools that can be left to their own devices remotely.

Under the hood Calibre recipes appear to be python scripts. For example, you might have a file Religion.recipe with instructions to download the last two days of entries from the blogs of Kimberly Knight, Rachel Held Evans, Fred Clark, James McGrath, Libby Anne, and Jonny Scaramanga (up to a maximum of 100 each) that looks like the following:

class BasicUserRecipe1448244083(AutomaticNewsRecipe):
    title                 = u'Religion'
    oldest_article        = 2
    max_articles_per_feed = 100
    auto_cleanup          = True

    feeds = [
             (u'Kimberly Knight', u''),
             (u'Rachel Held Evans', u""),
             (u'Slacktivist', u''),
             (u'Explorting Our Matrix', u''),
             (u'Love, Joy, Feminism', u''),
             (u'Leaving Fundimentalism', u'')

This can then be used directly from the command line with:

ebook-convert "Religion.recipe" "" --tags="News,Religion" --authors="Various" --title="Religion" --series="Religion RSS"

This only then needs to be sent to your kindle, which can be done by a number of methods including Calibre’s own calibre-smtp command, like so:

calibre-smtp --relay=" [for example]" --port=587 --username="[your@email or similar username]" --password="[Your.Password]" --subject="News delivery -" -a "" [Your@email] [] "News delivery (attached);" >> log.txt 2>&1

This may take some setting up, both letting Calibre use your email and allowing your kindle to receive it, but you can find that information elsewhere.

After you’ve got that to work you can put it together in a script, allowing any number of different such recipes to be called by much shorter commands, e.g.:

TODAY=$(date +"%F")
cd ~/calibre-recipies

rm "$"
echo "Starting $1 at $(date)" >> log.txt
ebook-convert "$2.recipe" "$" --pubdate=$TODAY --tags="News" --authors="Various" --title="$1" --series="$1 RSS" >> log.txt 2>&1
calibre-smtp --relay="[server]" --port=587 --username="[username]" --password="[password]" --subject="News delivery - $" -a "$" [email@address] [] "News delivery (attached); $" >> log.txt 2>&1
echo "End $1 at $(date)" >> log.txt

This could then be called with

# First "Religion" is the output name,
# second is the script name
./ "Religion" "Religion"

And that can be called at, say, 5am every weekday morning via the marvel that is cron with e.g.

20 5    * * Mon-Fri        /home/petra/calibre-recipes/ "Religion" "Religion"

There are, however, a few disadvantages: Not everything downloads properly all the time, and you often get random encoding errors. This is annoying, although I find you get used to it. It’s a great way to get you something to read on the train without needing internet as-you-read-it (just at home to download things) but not so great at keeping up with everything.

Still, you might be able to get it working for you, and there’s definitely a great deal that can be done to tweak it. For more information start with the documentation for the ebook-convert command.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s