Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

XPAddiction -- a new XP whoring tool

by jaldhar (Vicar)
on Jul 02, 2002 at 23:47 UTC ( #179026=CUFP: print w/replies, xml ) Need Help??

jcwren's node XPFixation -- The Essential Windows XP Whoring Tool presented an interesting tool which has two problems. It doesn't run on Linux and it doesn't use perl. We can't have that can we?

I set out to write something similiar. On my Linux box, I run a desktop environment called KDE. Rather than a tray icon, I decided to use a KDE program called AMOR (Amusing Misuse Of Resources) to display my XP status. AMOR makes a little animated character dance on top of whichever window has focus but more importantly it can also display some text in a bubble. KDE has an automation system called DCOP similiar to OLE (or whatever they're calling it this week) on Windows. While I believe there was a perl binding for DCOP at some point, I couldn't find it now. Luckily KDE also has a gateway to DCOP via XML-RPC (which can be accessed from perl with Frontier::RPC.) so I used that to control AMOR instead. I could also have used DCOP/XML-RPC to pop up a message box or play an MP3 via noatun (the KDE media player) if I wanted to.

How to get your XP? I could have scraped the HTML from the XP nodelet but that would have been tedious and prone to breakage. A better way is through the XP XML ticker. XML::Simple made short work of parsing it for the info I needed.

Anyway, without further ado, here is XPAddiction. I hope you like it and please send me any suggestions to enhance it.


!/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 = <XP>; 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 ('', { op => 'login', user => $user, passwd => $passwd, expires => '+10y', }); my $res = $ua->request($req); if ($res->is_success) { # get the ticker. $req = GET ('' +); 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(/,/, <KXMLRPCD>); 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 XM +L ticker at regular intervals and tell you if your XP has changed via XML-RPC t +o the B<amor> program. =head1 INSTALLATION Make the script executable. You may have to change the first line if B<Perl> is not in F</usr/bin> on your system. You will also need the B<Frontier::RPC>, B<LWP>, and B<XML::Simple> 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 l +ong as the prerequisites are met. In order for this script to do its' thing, the B<kxmlrpcd> and B<amor> programs from KDE must be running. In B<amor>'s options, "Allow application tips" must be selected. =head1 CONFIGURATION There are four values you can change in the configuration section at t +he 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<xpaddiction> 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 E<lt>jaldhar@braincells.comE<gt> =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

edited: Mon Jul 8 02:09:23 2002 by jeffa - added readmore tag

Replies are listed 'Best First'.
Perl bindings for KDE
by IlyaM (Parson) on Jul 04, 2002 at 11:43 UTC
Re: XPAddiction -- a new XP whoring tool
by Aristotle (Chancellor) on Jul 03, 2002 at 12:36 UTC
    Curse you! :) I was going to write a dockapp for the purpose.

    Makeshifts last the longest.

(jcwren) Re: XPAddiction -- a new XP whoring tool
by jcwren (Prior) on Jul 07, 2002 at 14:09 UTC

    Verra cool!

    You can avoid the username+password/cookie requirement by using '&for_user=vroom', or '&for_userid=979' to simplify it (thus requiring the user to only supply their username or home node ID number). The only difference is that the "votesleft" field will come back as -1, which shouldn't be a problem.

    The part I like about using the home node ID number is you no longer have to be concerned about users with stupid characters in their names.


    e-mail jcwren

      Thanks jcwren for the info. I tried something like that initially but didn't get it to work.

      And thankyou too IlyaM. When the perl bindings get stable, I may package them for Debian.


Re: XPAddiction -- a new XP whoring tool
by perlkid (Novice) on Jul 07, 2002 at 08:48 UTC
    I found the program very interesting, it is also compact (~100 lines or so) 
    So I thought I'll give it a try. I went and installed all the required modules
    using CPAN interactive. (that saved me a lot of time and effort, whew.., so many 
    dependencies or perhaps I never came across to use many of them) 
    I ran the program and got an error, may be it's something I didn't set it right.
    But couldn't seem to figure out.
    here is the error:
    500 Cann't connect to localhost:file::80 (Bad hostname 'localhost:file:')
    I spotted one line in the code, may be it has something to do with the error I got.
    If not, let me know, what could possibly cause the error. Thanks!
    in sub talktoamor
    my $rpc = Frontier::Client->new(url=> "http://localhost:$port/amor" )

    p.s. I also tried s/localhost/ ,but it gave same 500 error
      I got the same error.
      After starting the amor and kxmlrpcd, however, it worked :)

      From the POD:
      In order for this script to do its' thing, the kxmlrpcd and amor programs from KDE must be running. In amor's options, "Allow application tips" must be selected.

      ---- kurt
        I have both kxmlrpcd and amor running, and the option
        "Allow application tips" is set. But still getting,
        500 Cann't connect to localhost:file::80 (Bad hostname 'localhost:file:')
        :( Anything else? 
        I have KDE 2.1.2 on RH 7.1

      kxmlrpcd should be running. If not it won't work. You can only connect to localhost because you want to use the kxmlrpcd on your machine. If was running the service, specifiying it in the URL would make output show up there. But it isn't so that won't work at all.

      The problem is for some reason you can't make connections to kxmlrpcd. Could your firewall or iptables filtering etc. be blocking connections maybe? Try telneting directly to the port specified in $port on localhost. If you get "connection refused" and you are sure the server is up, I'm willing to bet that's the problem.


        Jaldhar, I totally like the creativity of the program and definitely easy to re +ad code :). Although, I haven't successfully made it to work yet. Just how much I want to see how it works and I know I am close to it! I ran the program in perl debugging mode, skip most part to the the su +b talktoamor. Along the way, I see it generates XML code with the message Hooray! .. + and it passed the line my $rpc = Frontier::Client->new(url=>"http://localhost:$port/amor") #With the debugging mode I see #url=>'http://localhost:file:///local_acct/.kxmlrpcd-socket-jm524W/amo +r' <b>$port</b> contains ':file:///....jm524W' <-- this is not my passwo +rd ;) There is no port number in it!

        Anyway, at this point, I am pretty certain that one of the module I in +stalled might be crapped out (I suspect the libwww) Thanks! I think I learn in the process, will let you know how it turn +out. -perlkid

        Edit by tye, change PRE to CODE around not-short lines

Re: XPAddiction -- a new XP whoring tool
by sheridan3003 (Beadle) on Jul 09, 2002 at 17:20 UTC
    Thanks for this. You gave me a great idea.
    I basically copied your talktoamor function and set it up as a small couple line perl program to notify me through kmail when I have mail. This was a great use for perl!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://179026]
Approved by ar0n
Front-paged by ariels
[1nickt]: jdporter Maybe try IPC::Run3
[LanX]: Sandy Koufax is indeed rude. .. oO
[chacham]: Re: Re: pattern matching -- feeling stoopit a poll idea about centrists, is +8 -5, used to be +6/-6 how apropos :)is +8
[chacham]: ...errr... Re: poll ideas quest 2015 (political centrist)
[chacham]: ooh, late, nighty nite everybody
[jdporter]: thanks, 1nickt1

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2017-05-24 21:02 GMT
Find Nodes?
    Voting Booth?