!/usr/bin/perl -w use strict; ################# # CONFIGURATION # ################# my $user = 'Your name'; my $passwd = 'Your password'; my $configdir = "$ENV{HOME}/.xpaddiction"; my $interval = 300; #### NO NEED TO EDIT ANYTHING BELOW THIS LINE #### use Frontier::Client; use HTTP::Cookies; use HTTP::Request::Common; use LWP::UserAgent; use XML::Simple; while (1) { unless ( -d $configdir ) { mkdir $configdir or die "Cannot create configuration directory\n"; } my $oldxp = 0; if ( -f "$configdir/xp" ) { open (XP, '+<', "$configdir/xp") or die "Cannot open xp file\n"; $oldxp = ; chomp $oldxp; close XP; } my $xp = getxp($user, $passwd, $configdir); my $delta = $xp - $oldxp; if ($delta > 0) { talktoamor("Hooray $user! Your Perl Monks XP increased by $delta to $xp."); } elsif ($delta < 0) { talktoamor("Sorry $user! Your Perl Monks XP decreased by " . abs($delta) . " to $xp."); } else { talktoamor("Hey $user! Your Perl Monks XP is $xp."); } open (XP, '>', "$configdir/xp") or die "Cannot open xp file\n"; print XP $xp; close XP; sleep $interval; } sub getxp { my ($user, $passwd, $configdir) = @_ or die; my $ua = LWP::UserAgent->new( cookie_jar => HTTP::Cookies->new(file => "$configdir/cookies.txt", autosave => 1), ); # simulate a login and get a cookie my $req = POST ('http://perlmonks.org/index.pl', { op => 'login', user => $user, passwd => $passwd, expires => '+10y', }); my $res = $ua->request($req); if ($res->is_success) { # get the ticker. $req = GET ('http://perlmonks.org/index.pl?node=XP%20xml%20ticker'); my $res = $ua->request($req); if ($res->is_success) { my $ticker = XMLin($res->content); return $ticker->{XP}->{xp}; } } # something must have gone wrong. Display LWPs' error message warn 'Uh-oh!: ' . $res->status_line . "\n"; } sub talktoamor { my ($message) = @_ or die; open(KXMLRPCD, '<', "$ENV{HOME}/.kxmlrpcd") or die "Can't open configuration file. Is kxmlrpcd running?\n"; my ($port, $auth) = split(/,/, ); chomp $auth; close KXMLRPCD; my $rpc = Frontier::Client->new(url => "http://localhost:$port/amor") or die "Cannot make RPC connection. Is amor running?\n"; $rpc->call('showTip', $auth, $message); } __END__ =pod =head1 NAME xpaddiction -- XP whoring for the rest of us =head1 SYNOPSIS B<./xpaddiction &> =head1 DESCRIPTION This script will log you into the Perl Monks website, access the XP XML ticker at regular intervals and tell you if your XP has changed via XML-RPC to the B program. =head1 INSTALLATION Make the script executable. You may have to change the first line if B is not in F on your system. You will also need the B, B, and B packages from CPAN plus version 2 or above of the KDE desktop environment. This script has so far only been tested on Linux and KDE 3.0.2 but should work elsewhere as long as the prerequisites are met. In order for this script to do its' thing, the B and B programs from KDE must be running. In B's options, "Allow application tips" must be selected. =head1 CONFIGURATION There are four values you can change in the configuration section at the top of the script: =over 4 =item I<$user> Your Perl Monks user ID. =item I<$passwd> Your Perl Monks password. =item I<$configdir> Where you want B to store its' stuff. =item I<$interval> The period in seconds the script should wait before checking your XP again. The default is 300 (5 minutes.) =back =head1 AUTHOR Jaldhar H. Vyas Ejaldhar@braincells.comE =head1 LICENSE This code is free software under the Crowley Public License ("Do what thou wilt shall be the whole of the license") =head1 VERSION 1.0 -- Jul 2, 2002 =cut