Make your own free website on
I wanted to see when a certain product, data cable for a samsung phone, would be ready. I did some looking at their web page (see commented out $url statement), and found that they use AJAX to update their inventory status. So I built the perl page below to check what I was interested in.
  #!/usr/bin/perl -w

  # by Michael Mayer-Oakes
  # 6/27/2009

  use strict;
  use WWW::Mechanize;
  use diagnostics;

  my ($p, $nValue, $rowsreturned, $htmlCode, $length, $return_val, 
  	$script, $url, $content, @results); 
  my $mech = WWW::Mechanize->new(onwarn => undef);

  # first checked the page that told me "out of stock"
  #my $url = 'http://';

  # use their ajax url
  $url ='';
  # got this from the page showing the "out of stock" message, check the javascript section
  #  note, multiple "product_id" can be sent as pipe delimited entries
  $content = 'url=';
  $mech->post($url, content => $content);
  # results

  $htmlCode = $mech->content();
  @results = split(/\|/, $htmlCode);

  # if any problems or if it comes back as available then show the results
  if (!defined($results[6]) || $results[6] eq "Y") {
    print "Looks like the Samsung Data Cable is available!\n";
    # don't print first entry, has CRLFs and other stuff
    #print "length ".length($results[0])."\n";
    #print "PRODUCT_ID ".$results[0]."\n";
    print "PRODUCT_ID PKT200BBEG/STD\n";
    print "MSRP ".$results[1]."\n";
    print "PROMO_FROM ".$results[2]."\n";
    print "PROMO_TO ".$results[3]."\n";
    print "PROMO_PRICE ".$results[4]."\n";
    print "PROMO_FLAG ".$results[5]."\n";
    print "AVAILABILITY_FLAG ".$results[6]."\n";

  # end of script
Now a simple shell script, to email the results, if anything is reported
  # by Michael Mayer-Oakes
  # June 27, 2009

  # check if data cable is ready, if so email to myself
  # protect against NULL emails
  if [ "$DataCable" != "" ]
	echo "$DataCable" | mail -s "Data Cable for Sumsung Phone IN STOCK!"
Lastly, our good friend cron
  5 1 * * * /path/to/script/samsungCheck
And get ready for an email, when the data cable is back in stock!