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


In reply to Wootoff monitor by zigdon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.