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);
}