|
|
#1 |
|
Enthusiast
![]() Posts: 40
Karma: 10
Join Date: Oct 2012
Device: Pocket Book Touch HD3
|
[How To] Running Calibre server as a news server
Hi,
I have been trying to setup calibre as a stand alone server using the command line only (without the gui). It is to fetch newspapers on a daily basis, tagging them correctly and deleting newspapers which are older than 2 days. Here's my approach. First I have to get news into calibre server database. Therefore I wrote a simple bash script that is run once a day in the morning as a cron job; for example "The Guardian": Code:
#!/bin/sh # The Guardian cd <PATH whereever you store your calibre scripts> rm guardian.epub ebook-convert ./PATH_TO_CALIBRE_RECIPES/calibre-recipes/guardian.recipe guardian.epub --output-profile=kobo && ebook-meta guardian.epub --tag dailynews&& calibredb add guardian.epub I can now use the web interface of the server to fetch my daily newspaper. I could also mail the newspaper to the device of my linking. Just put the following snippet at the end of the bash script above: Code:
calibre-smtp -r <email server domain> -u <username email address> -p <secret_password> --port 25 <server email address> <recipient email address> 'Good morning! Here's your new Guardian. Have fun!' -a guardian.epub -s 'Your new Guardian' Code:
#!/usr/bin/perl -w
#
##################
# file: cal_del_old_dailynews.pl
# author: Sebastian Singer
# version: 1.1
# disclaimer: No warranty whatsoever!
#
# What this script does:
# This script deletes daily newspapers from Calibre Server
# which are older than two days. Putting this script in crontab
# automates the process.
#
# How this script works:
# 1. Generate a list of newspapers older than two days
# 2. Extract the epub id's from this list
# 3. Hand over the id's to calibredb for removal
#
# Notes:
# For the script expected to work you have to tag the epubs. So if
# you fetch your daily newspaper for your calibre server on the command line
# don't forget tagging it. Otherwise you won't find it afterwards.
# Here is a possible way (a bash script) to fetch "The Guardian"
# on a daily basis. This script can also be put into crontab:
#
# #!/bin/sh
# rm guardian.epub
# ebook-convert ../PATH_TO/calibre-recipes/guardian.recipe guardian.epub --output-profile=kobo &&
# ebook-meta guardian.epub --tag dailynews &&
# calibredb add guardian.epub
#
######################
#
# 1. Generate a list of newspapers older than two days
open(CALINDEX,">","old_dailynews.txt");
my @get_list = (" CALIBRE_OVERRIDE_LANG=en calibredb list --search 'date:<1daysago and tags:dailynews' > old_dailynews.txt");
my @get_list_exec = system(@get_list);
close (CALINDEX);
# 2. Extract the epub id's from this list
# 2.1. extract id's:
open(CALINDEX,"old_dailynews.txt");
my $file = CALINDEX;
my @cal_index;
foreach my $line ( <$file> ) {
if ( $line =~ /^\d/) {
push @cal_index, substr $line,0,4;
}
}
chomp @cal_index;
# 2.2 substitue empty spaces by commas:
open(DELINDEX,">","del_cal_index.txt");
print DELINDEX @cal_index;
close(DELINDEX);
open(DELINDEX,"del_cal_index.txt");
my $cal_ids = <DELINDEX>;
$cal_ids =~ s/\s/,/g;
# get rid of the last trailing comma:
$cal_ids =~ s/,$//;
chomp $cal_ids;
# print $cal_ids; # uncomment just for checking
close (DELINDEX);
close(CALINDEX);
# 3. Hand over the id's to calibredb for removal
system("/usr/bin/calibredb","remove",$cal_ids) == 0
or die "system failed: $?";
I am aware that calibre is written in python and so it would be suitable to write a python script instead of using perl. But on the one hand I don't understand python very well (sorry?!). So I better stuck with a language I had been working with before. On the other hand I am far from being a perl or bash programmer. So please don't mind the simple structure of the scripts. I hope that someone will find this "cli approach" helpful. Hints to improve this way or to correct errors are always welcome. Cheers, Sebastian |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Running Calibre on Server | godlich | Recipes | 2 | 02-09-2012 01:57 PM |
| Running Calibre content server as a service | mathia | Related Tools | 31 | 07-04-2011 10:34 AM |
| Calibre-Server - Ubuntu 10.10 - Running but not serving | dcmarquardt | Calibre | 10 | 04-05-2011 08:33 PM |
| Running Calibre on Terminal Server | JeffAlan66 | Calibre | 2 | 08-12-2010 03:00 PM |
| Trouble running calibre-server | ould | Calibre | 0 | 04-16-2010 03:18 PM |