use OpenSRF::AppSession;
use OpenILS::Utils::CStoreEditor;
use OpenILS::Utils::Cronscript;
+use OpenILS::Utils::RemoteAccount;
binmode(STDOUT, ":utf8");
my %defaults = (
- 'osrf-config=s' => '/openils/conf/opensrf_core.xml',
- 'start-date=s' => DateTime->now->strftime('%F'),
- 'end-date=s' => '',
- 'event-defs=s' => '',
- 'verbose' => 0
+ 'osrf-config=s' => '/openils/conf/opensrf_core.xml',
+ 'start-date=s' => DateTime->now->strftime('%F'),
+ 'end-date=s' => '',
+ 'event-defs=s' => '',
+ 'out-file=s' => '',
+ 'remote-account=s' => 0,
+ 'nolockfile' => 1,
+ 'verbose' => 0,
+ 'cleanup-file' => 0 # remove output file when done
);
sub help {
Collect CSV notification output and deliver to 3rd party
-# collection notifications for today for the selected defs
-$0 --event-def 104,105,106
+# Collect a week of notifications
-# collect a week of notifications
-$0 --event-def 104,105,106 --start-date 2012-01-01 --end-date 2012-01-07
+$0 \
+ --event-def 104,105,106 \
+ --start-date 2012-01-01 \
+ --end-date 2012-01-07 \
+ --out-file /var/run/evergreen/csv/2012-01-07.notify.csv
+ --remote-account 6
HELP
exit;
my $verbose = $opts->{'verbose'};
my $start_date = $opts->{'start-date'} || '';
my $end_date = $opts->{'end-date'} || '';
+my $out_file = $opts->{'out-file'} || '&STDOUT';
+my $remote_account = $opts->{'remote-account'};
my @event_defs = split(/,/, $opts->{'event-defs'});
print "processing event_defs = @event_defs\n";
print "start_date = $start_date\n";
print "end_date = $end_date\n";
+ print "out_file = $out_file\n";
}
+open(OUTFILE, ">$out_file") or
+ die "unable to open out-file '$out_file' for writing: $!\n";
+
my %date_filter;
$date_filter{run_time} = {'>=' => $start_date} if $start_date;
$date_filter{run_time} = {'<' => $end_date} if $end_date;
);
# header
-print '"Media Type","Language","Notice Type","Notification Level",';
-print '"Patron Number","Patron Title","Patron First Names","Patron Surname",';
-print '"Telephone Number","Email Address","Library Code","Site Code",';
-print '"Site Name","Item Barcode","Due Date","Item Title","Transaction ID"';
-print "\n";
+print OUTFILE '"Media Type","Language","Notice Type","Notification Level",';
+print OUTFILE '"Patron Number","Patron Title","Patron First Names","Patron Surname",';
+print OUTFILE '"Telephone Number","Email Address","Library Code","Site Code",';
+print OUTFILE '"Site Name","Item Barcode","Due Date","Item Title","Transaction ID"';
+print OUTFILE "\n";
# dump the CSV chunk from each event output
while (my $resp = $req->recv(timeout => 12000)) {
last;
};
my $content = $resp->content or next;
- print $content->{data};
+ print OUTFILE $content->{data};
+}
+
+# no output file? nothing left to do
+exit unless $opts->{'out-file'};
+
+if ($remote_account) {
+
+ my $racct = $o->editor->retrieve_config_remote_account($remote_account);
+ die "No such remote account $remote_account" unless $racct;
+
+ my $type;
+ my $host = $racct->host;
+ ($host =~ s/^(S?FTP)://i and $type = uc($1)) or
+ ($host =~ s/^(SSH|SCP)://i and $type = 'SCP');
+
+ my $acct = OpenILS::Utils::RemoteAccount->new(
+ type => $type,
+ account_object => $racct,
+ local_file => $out_file,
+ remote_file => $out_file
+ );
+
+ my $res = $acct->put;
+
+ die "Unable to push to remote server [$remote_account] : " .
+ $acct->error . "\n" unless $res;
+
+ print "Pushed file to $res\n" if $verbose;
}
+
+if ($opts->{'cleanup-file'}) {
+ unlink($out_file) or die "Unable to clean up file '$out_file' : $!\n";
+}
+
+