From bbb9ded0a6c0eb3c076ca744b152d56f922fc1c9 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Mon, 2 Mar 2015 02:29:06 -0600 Subject: [PATCH] Add daily digest script --- Makefile | 2 +- aux/bin/daily-digest | 70 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100755 aux/bin/daily-digest diff --git a/Makefile b/Makefile index caf187f..947c935 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ install-environment: all docs $(ENV_DIR)/www/doc/perl \ $(ENV_DIR)/www/images install --mode 755 blerg.cgi aux/cgi/*.cgi $(ENV_DIR)/lib/cgi-bin/ - install --mode 755 blergtool blerglatest $(ENV_DIR)/bin/ + install --mode 755 blergtool blerglatest aux/bin/* $(ENV_DIR)/bin/ install --mode 644 www/favicon.gif www/favicon.ico www/index.html \ www/welcome.html \ $(ENV_DIR)/www/ diff --git a/aux/bin/daily-digest b/aux/bin/daily-digest new file mode 100755 index 0000000..18ae52b --- /dev/null +++ b/aux/bin/daily-digest @@ -0,0 +1,70 @@ +#!/usr/bin/perl +use Blerg::Database; +use Mail::Message; +use POSIX qw/strftime/; +use strict; +use v5.10; + +my $t1 = time; +my $t0 = $t1 - 86400; + +sub send_email { + my ($username) = @_; + + if (!Blerg::Database::exists($username)) { + return; + } + + my $email_conf_path = Blerg::Database::configuration->{data_path} . "/$username/email"; + if (!-f $email_conf_path) { + return; + } + + open CONF, $email_conf_path; + my $email = ; + close CONF; + + my $blerg = Blerg::Database->open_existing($username); + my @items = $blerg->subscription_list; + $blerg->close; + + if (!@items) { + return; + } + + my $feeditems; + for my $i (@items) { + use Data::Dumper; + $blerg = Blerg::Database->open_existing($i->{author}) + or next; + + my $ts = $blerg->timestamp($i->{record}); + if ($ts >= $t0 && $ts < $t1) { + my $data = $blerg->fetch($i->{record}); + next if !defined $data; + my $date = strftime('%T %b %-d %Y (%Z)', localtime($ts)); + $feeditems .= "== $i->{author} at $date\n\n$data\n\n\n"; + } + + $blerg->close; + } + + if (!defined $feeditems) { + return; + } + + Mail::Message->build( + From => Mail::Address->new('BlergBot', 'noreply@blerg.cc'), + To => Mail::Address->new($username, $email), + Subject => 'Blërg Daily Digest', + Mail::Message::Field->new('Content-Type', 'text/plain', 'charset="utf8"'), + data => <send; +} + +send_email('bytex64'); -- 2.25.1