#!/usr/bin/perl
# This is scarlet.pl, by Dieter D'Hoker
# prints how much data you've used up on your scarlet account on the command line
# scarlet.pl <username> <password>
use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Cookies;
#use HTML::Entities;
# you can give username and password directly: "perl scarlet.pl <username> <password>"
my $username = $ARGV[0];
my $password = $ARGV[1];
# if username or password is not given, ask for it
if (not $username){
print "Username:\n";
$username = <STDIN>;
chomp $username;
}
if (not $password){
print "Password:\n";
$password = <STDIN>;
chomp $password;
}
# initialize UserAgent, Request, Result vars for LWP
my ($ua,$req,$res);
#start the user agent
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0");
$ua->cookie_jar( HTTP::Cookies->new(
'file' => '\cookies',
# where to read/write cookies
'autosave' => 1,
# save it to disk when done
));
# The sequence of urls that has to be visited
my @urls = ('http://customercare.scarlet.be/index.jsp?language=nl',
"http://customercare.scarlet.be/logon.do?language=nl&username=$username&password=$password",
'http://customercare.scarlet.be/usage/dispatch.do');
#get all the above urls
foreach my $url(@urls){
$req = HTTP::Request->new(GET => $url);
$res = $ua->request($req);
if (not $res->is_success){
print(' Something went wrong at: ',$url,' : ',$res->status_line, "\n");die;
}
}
#put the HTML-source of the last URL fetched in $source
my $source= $res->content;
#parse the source and print everything
print "\nUsage for $username:\n";
print "-" x length("Usage for $username:") . "\n\n";
if ($source =~ /<p>U hebt <b>(\d\d) \%<\/b>/i){
my $percent = $1;
my $used = '#' x ($percent/2);
my $rest = '.' x ((100-$percent)/2);
my @data = ($source =~ /\<th class=\"digit\"\>(.+)\<\/th\>/ig);
print "DL:\t$data[0] \nUL:\t$data[1] \n+\t---------\nTOT:\t$data[2]\n";
print "\n[$used$rest] ($percent\%)\n";
}
else{ print "Could not parse website\n";die;}