Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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


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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found