Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Thursday December 04, 2003
02:21 PM

This is the END

[ #16170 ]

Andy Lester sent me a program to look at O'Reilly weblog stats, which webloggers can get on themselves (maybe others, too, I think). I wanted to add a little to that, and I got carried away.

I get this output now, which is just what I want. It has the number of times someone has looked at the entry, its rank in the O'Reilly system, and the title. I could also add the date of entry and other things, but I do not care about that so much.

O'Reilly Net report for 12/4/2003
  Views   Rank   Title
------ ------   --------------------
  29196    783   Controlling iTunes with Perl
  23211   1131   Cleaning iTunes
   400   3067   The ability to innovate

I ended up with a subclass-able package, and although I could turn this into a full distribution, I need to pack to go back to the sandbox.

I really just wanted to add a bit to the program, and it was easy enough to create the package since I had moved everything into subroutines, I just did it.

I then added a just_do_it method, which might look like a run() function from some computer sccience student's C program. I want to run the little program once the class is defined, but I want to put all the class stuff at the end because it is the less interesting stuff. For instance, the username and password is more important than the class particulars.

Now, if someone wants to turn this into a full module and release it to CPAN (please do), other people can use it while overriding some of the methods, like print_results, which is the only thing that I wanted to change in Andy's version.

#!/usr/bin/perl -w
use strict;
 
END {
    my $user     = "bar";
    my $password = "foo";
    my $verbose  = 0;
 
    my $stats = MyStats->just_do_it( $user, $password, $verbose );
    }
 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
package MyStats;
 
# LOTS OF STUFFED SNIPPED
 
sub just_do_it
    {
    my $class = shift;
 
    my $self = $class->new( @_ );
 
    $self->get_page->cleanse_page->extract_results->
        sort_results->print_header->print_results;
 
    return $self;
    }
 
sub print_header
    {
    my $self = shift;
 
    my @times = localtime();
    print "O'Reilly Net report for ",
        join( "/", $times[4]+1, $times[3], $times[5]+1900 ), "\n";
 
    $self;
    }

The SourceForge CVS browser still seems slow to update, but you can use anonymous CVS to checkout the sources if you cannot look at them in the browser. The password is "anonymous". Enter that after using cvs login.

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/brian-d-foy login
 
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/brian-d-foy co ora-weblog-stats

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.