#!/usr/bin/perl -w
#
# partyflock v0.1
# http://brink.st/config/files/perl/partyflock.pl
#
# flock is a handy tool for Partyflock admins to show the amount of
# active tickets without the necessity to log into the site.
#
# Copyright (C) 2007 Remco B. Brink <remco@rc6.org>
#
# 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 2
# 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.
#
# The GNU General Public License is available at:
# http://www.gnu.org/copyleft/gpl.html

use strict;

my $flock_nick = 'xxxxxx'; # Your Partyflock username
my $flock_pass = 'xxxxxx'; # Your Partyflock password

use WWW::Mechanize;
use HTML::TokeParser;
use Data::Dumper;

my $agent = WWW::Mechanize->new();

# Head to the login page
$agent->get("http://vip.partyflock.nl/user/login.html");

# First form on the page is our login form
$agent->forms(1);

# Fill in username and password
$agent->field("NEW_FLOCK_NICK", $flock_nick);
$agent->field("NEW_FLOCK_PASSWD", $flock_pass);
$agent->click();

# Fetch the content of that page for TokeParser
my $stream = HTML::TokeParser->new(\$agent->{content});
my $helpdesk;

# Find the correct tag for helpdesk tickets
my $tag = $stream->get_tag("span");
$tag = $stream->get_tag("span");
$tag = $stream->get_tag("span");

if ($tag->[1]{class} and $tag->[1]{class} eq "underline") {
  $helpdesk = $stream->get_trimmed_text("/span");
}

print "Current number of tickets: $helpdesk\n";

