http://www.perlmonks.org?node_id=421440


in reply to Abstract: rate of popular growth for Perl

Tommy,
You need to choose a tangible set of factors to measure since the concept of "popular" is very subjective. One ruler might be the population growth of a particular community such as Perl Monks. To that end, the following piece of code will extract dates and counts for approximately the first 550 new users.

Please do not modify this code and run it without thinking about the consequences. The sleep interval is likely not long enough if you are going to hammer jcwren's server for every single user. Another useful feature would be to have signal handling allowing persistency of data (DB) even when you abort early. Additionally, it should be modified to allow you to resume where it left off. This would make gathering the stats over time much more server friendly.

#!/usr/bin/perl use strict; use warnings; use HTML::TableContentParser; use WWW::Mechanize; use constant DATE => 3; use constant STATS => 4; my %opt = ( url => 'http://tinymicros.com/pm/index.php?goto=monkstats&sortopt= +13&sortlist=1,3&', end => 500, pos => 0, ); my $mech = WWW::Mechanize->new( autocheck => 1 ); my %date; while ( $opt{pos} <= $opt{end} ) { $mech->get( $opt{url} . '&start=' . $opt{pos} ); my $table = HTML::TableContentParser->new()->parse( $mech->content +() ); for my $row ( @{ $table->[ STATS ]{rows} } ) { my $stamp = ${ $row->{cells} }[ DATE ]{data}; next if ! $stamp; ($stamp) = $stamp =~ m|<NOBR>(.*)</NOBR>|; $date{ substr($stamp, 0, 10) }++; } $opt{pos} += 50; select(undef, undef, undef, 0.75); } print "$_,$date{$_}\n" for sort keys %date;
In reality, you would want to consider more factors like the ratio of writeups to users, how many users haven't logged in for more than a certain amount of time, etc.

Cheers - L~R