#!/usr/bin/perl
use strict;
use warnings;
use POSIX 'strftime';
use Date::Calc qw /Today Delta_Days/;
use LWP::Simple;
sub plotme;
my $outdir = "/home/abigail/WWW";
$outdir = "/tmp" unless -d $outdir;
my $output = "$outdir/monks.html";
my $outfile = "$outdir/Images/monks.png";
my $data = "$outdir/Data/monks.dat";
sub logme {
my ($xp, $arts) = @_;
my $today = strftime "%Y-%m-%d" => localtime;
open my $fh => "+<", $data or die "Failed to open $data: $!\n";
my $first_line = <$fh>;
my $first_date = (split /:/ => $first_line, 2) [0];
while (<$fh>) {
my ($date, $xp, $arts) = split;
if ($date =~ /^$today/) {
close $fh;
return $first_date;
}
}
printf $fh "%s: %6d %6d\n" => $today, $xp, $arts;
close $fh or die "Failed to close $data: $!\n";
return $first_date;
}
my $url = "http://www.perlmonks.org/index.pl?node_id=169744";
my $content = get ($url) or die "Failed to fetch $url\n";
my ($since) = $content =~ m!
User \s+ since: | \s+
([^<]+) | !x;
my ($exp) = $content =~ m!Experience: | \s+
(\d+) | !x;
my ($arts) = $content =~ m!Writeups: | \s+
]+>(\d+) | !x;
die "Failed to find 'User since'.\n" unless defined $since;
die "Failed to find 'Experience'.\n" unless defined $exp;
die "Failed to find 'Write ups'.\n" unless defined $arts;
unless ($since =~ /([A-Z][a-z]+)\s+(\d+),\s+(\d+)/) {
die "Failed to parse $since.\n";
}
my %M = qw /Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12/;
my ($month, $day, $year) = ($M {$1}, $2, $3);
my $start = "$2 $1 $3";
my $nr_of_days = Delta_Days $year, $month, $day, Today;
my $exp_per_day = sprintf "%.1f" => $exp / $nr_of_days;
my $arts_per_day = sprintf "%.1f" => $arts / $nr_of_days;
my $exp_per_art = sprintf "%.1f" => $exp / $arts;
my $first_log = logme $exp, $arts;
my ($s_y, $s_m, $s_d) = split /-/ => $first_log;
$first_log = strftime "%e %B %Y" => 0, 0, 0, $s_d, $s_m - 1, $s_y - 1900;
plotme;
#
# HTML generating stuff.
#
my $now = strftime "%e %B %Y" => localtime;
open my $of => ">", $output or die "Failed to open $output: $!\n";
select $of;
print << "--";
Perl Monk Postings
Home
Perl Monk Postings
I'm a frequent poster on Perlmonks.
My first post dates from $start. Since then, I gathered $exp experience
points, writing $arts posts. This comes to $arts_per_day articles per day on
average, and $exp_per_day experience points per day.
It doesn't account to $exp_per_art experience per article,
because you can get heaps of experience
for just connecting to the site, or voting on other people.
Below is a graph showing the experience progress since $first_log.
It should be noted that experience points don't mean anything.
Copyright 2003 by Abigail.
Page last modified: $now.
Comments to: \$web\$\@abigail.nl
|
--
close $of or die "Failed to close $output: $!\n";
chmod 0644 => $output or die "Failed to chmod $output: $!\n";
sub plotme {
open my $plot => "| gnuplot" or die "Failed to open pipe: $!\n";
print $plot <<"--";
set terminal png color
set out "$outfile"
set xdata time
set timefmt "%Y-%m-%d:"
set key left top Left reverse samplen 2 title "Legend" box
set grid xtics ytics
set xtics nomirror
set ytics nomirror
set y2tics nomirror
set yrange [0:]
set y2range [0:]
set ylabel "XP"
set y2label "Postings"
plot "$data" using 1:2 smooth unique axis x1y1 title "Perlmonks XP", \\
"$data" using 1:3 smooth unique axis x1y2 title "Nr of postings"
--
close $plot or die "Failed to close pipe: $!\n";
chmod 0644 => $outfile or die "Failed to chmod $outfile: $!\n";
}
__END__
This program is copyright 2003 by Abigail.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.