useperl-journal-update

koschei on 2002-03-04T00:59:37

Since russell asked:

[1003][iain@ouroboros]0% cat useperl-journal-update #!/usr/local/bin/perl -w

use strict; use Storable; use Mail::Sendmail; use WWW::UsePerl::Journal; use IPC::Open2;

my $username = 'koschei'; my $j = WWW::UsePerl::Journal->new($username); my @entries = $j->recentarray; my $old = {}; $old = retrieve 'cache' if -f 'cache';

my $body;

foreach my $ent (reverse @entries) { my $id = $ent->id.'-'.$ent->user; print "$id\n"; next if exists $old->{$id}; my ($user,$jid,$subject,$content) = ($ent->user, $ent->id, $ent->subject, $ent->content);

my $child = 'lynx -stdin -dump'; my($rdrfh, $wtrfh); my $pid = open2($rdrfh, $wtrfh, (split /\s/, $child)); print $wtrfh $content; $wtrfh->close; my $fcontent = ''; while (<$rdrfh>) { $fcontent .= $_; } $rdrfh->close;

$body .= <
------------------------------------------------------------------------ From ${user}'s journal: ( http://use.perl.org/user/$user/journal/$jid )

>>> $subject

$fcontent

EOF $old->{$id} = time; }

$old = { map { $_, time } ((sort { $old->{$a} <=> $old->{$b} } keys %$old)[0..50]) };

store $old, 'cache';

my %mail = ( To => 'journals@dellah.anu.edu.au', From => 'journals@dellah.anu.edu.au', Subject => 'use.perl.org Journals', Body => $body, );

my $status = sendmail(%mail); warn $status;


Oops

koschei on 2002-03-06T02:32:41

Naturally, in that sort nearish the bottom, $a and $b should be around the other way (or bung reverse in the appropriate position).