View Single Post
Old 09-30-2015, 02:58 AM   #3
sws
Enthusiast
sws began at the beginning.
 
sws's Avatar
 
Posts: 40
Karma: 10
Join Date: Oct 2012
Device: Pocket Book Touch HD3
Hi,
I wrote a perl script for this problem. I am not really good at perl. I am quite sure that there are solutions more elegant than mine but it works for me. So here is my code. Take care to use YOUR tags in line 17 if you did not choose the german word for dailynews ("Tageszeitung")

Code:
#!/usr/bin/perl -w

# file: cal_ex_alt_zeit.pl
# Author: Sebastian
# Version: 1.2
#
# This script deletes news from calibre database that are older than 2 days
# Three steps to do this:
# 1. collect a list of old newspapers
# 2. extract the IDs of those old newspapers
# 3. tell calibredb to delete those IDs



# 1. Collect a list of old newspapers
open(CALINDEX,">","old_newspapers.txt");
my @get_list = (" CALIBRE_OVERRIDE_LANG=en calibredb list --search 'date:<1daysago and tags:Tageszeitung' > old_newspapers.txt");
my @get_list_exec = system(@get_list);
close (CALINDEX);

# 2. extract the IDs  of old newspapers
# 2.1. extract IDs 
open(CALINDEX,"old_newspapers.txt");my $file = CALINDEX;
my @cal_index;
foreach my $line ( <$file> ) {
        if ( $line =~ /^\d/) {
        push @cal_index, substr $line,0,5;
        }
}
chomp @cal_index;

# 2.2 substitute blank characters by commata
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;
$cal_ids =~ s/,$//;
chomp $cal_ids;
print $cal_ids;
close (DELINDEX);
close(CALINDEX);

# 3. give list of IDs to calibredb for deletion:
system("/usr/bin/calibredb","remove",$cal_ids) == 0
        or die "system failed: $?";
Regards,
Sebastian

Last edited by sws; 10-01-2015 at 03:47 AM.
sws is offline   Reply With Quote