#!/usr/bin/perl
# Script Name: askubuntu-hof.pl
# Author: Nathan Handler <nhandler@ubuntu.com>
# Usage: perl ./askubuntu-hof.pl [Number of Users]
# Number of Users is an optional number of users to display in the list.
# Defaults to displaying the top 10 users.
# Copyright (C) 2010 Nathan Handler <nhandler@ubuntu.com>
# License: GNU General Public License
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in the /usr/share/common-licenses/GPL-3 file.

use strict;
use warnings;
use LWP::Simple;

my $num = $ARGV[0] || 10;
if($num > 30) {
	warn "Number of Users must be less than or equal to 30. Falling back to 10 users.\n";
	$num=10;
}
$num--;

my $url = 'http://stackexchange.com/leagues/31/week/askubuntu';

my $content = get($url);
die "Couldn't get $url" unless defined $content;

my(@users)=$content=~m/<h2>(.*?)<\/h2>/isg;
shift(@users);	#Necessary to remove the "Ubuntu Q&A for Ubuntu users and developers" entry above the user list
my(@trep)=$content=~m/<span class="number">([\d,]+)<\/span> total reputation/isg;
my(@wrep)=$content=~m/<span class="number">([\d,]+)<\/span> week reputation/isg;

for my $i (0 .. $num) {
	print $i+1 . " $users[$i] ($trep[$i] / $wrep[$i])\n";
}

