Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Wootoff monitor

by zigdon (Deacon)
on Aug 18, 2006 at 14:17 UTC ( #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
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? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2019-05-25 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (151 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!