Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Wootoff monitor

by zigdon (Deacon)
on Aug 18, 2006 at 14:17 UTC ( [id://568159]=CUFP: print w/replies, xml ) Need Help??

Silly little script to keep track of the currently running Wootoff (http://www.woot.com):
#!/usr/bin/perl #===================================================================== +========== # # FILE: wootoff.pl # # USAGE: ./wootoff.pl # # DESCRIPTION: Monitor woot.com and alert when there are changes # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Zigdon # VERSION: 1.0 # CREATED: 08/17/2006 09:54:43 AM EDT # REVISION: $Id: wootoff.pl 70 2006-08-17 22:30:27Z dan $ #===================================================================== +========== use strict; use LWP::Simple; use HTML::TreeBuilder; use Date::Manip; my $URL = "http://www.woot.com"; my $oldtitle; my ($woottime, $eta); $|++; my $idle = 0; while (1) { my ($title, $price, $percent) = &update; if ($title ne $oldtitle) { my $now = scalar localtime; exec("xmessage '$now - NEW WOOT!\n$title\n$price' 2>/dev/null") +unless fork; print "\n", UnixDate(ParseDate("now"), '%H:%M:%S'), " - NEW WOOT +!\n"; $woottime = time; $oldtitle = $title; } $eta = ParseDateDelta(int((time - $woottime) / (100 - $percent) * 10 +0)) if $percent < 99; my $etatext; if ($eta) { my $delta = DateCalc("now", "epoch $woottime"); $eta = DateCalc($delta, $eta); $etatext = Delta_Format($eta, 0, '%mhm, %svs'); $eta = DateCalc("now", $eta); $eta = UnixDate($eta, '%H:%M:%S'); } else { $eta = "N/A"; } print UnixDate(ParseDate("now"), '%H:%M:%S'), " - $title - $price ($ +percent\% eta: $etatext $eta)\r"; if ($idle++ > 600) { print "\n"; $idle = 0; } sleep 30; } sub update { my $html; until ($html = get $URL) { warn "Can't retrieve $URL!"; sleep 5; } my $tree = HTML::TreeBuilder->new_from_content($html) or die "Can' +t parse html!"; my $title = $tree->look_down(_tag => "h3", id => "ctl00_ContentPla +ceHolder_TitleHeader")->as_text; my $price = $tree->look_down(_tag => "span", id => "PriceSpan")->a +s_text; my $percent = $tree->look_down(_tag => "div", class => "bar")->att +r_get_i("style"); ($percent) = ($percent =~ /(\d+)/); return ($title, $price, $percent); }

-- zigdon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://568159]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found