#!/usr/bin/perl use LWP::UserAgent; use Net::SMTP; $ua = LWP::UserAgent->new; my ($req, $match, $res, $name, $url, $price, $readPath, $writePath, $companyName, $ccemail); my $changes=""; my $searchString=""; my $searchString2=""; $email = 'wmkzin@hotmail.com'; # $tag represents a tag in html $tag = "<[^>]*>"; $readPath = "/home/autotasks/pricemonitor/"; $companyName = "LensMart"; $searchString = qr|^Price: \$([0-9]+\.[0-9]+)|; $searchString2 = qr|^Price: $tag\$([0-9]+\.[0-9]+)|; open( CONTACTS, "<$readPath$companyName" ) ; # list being read open( CONTACTS2, ">$readPath.$companyName"); # new list being generated while( ) { chomp($_); ($name, $url, $price) = split(/###/, $_); $savename = $name; $name =~ s/\(/\\(/g; $name =~ s/\)/\\)/g; $req = HTTP::Request->new(GET => $url); $res = $ua->request($req); $_ = $res->content; # the "if" statement below looks for the product name and price if( /$searchString/ ) { $match = $1; # check if price is the same if( $1 == $price ) {} else { # price changed, so add to "changes" list $changes .= "$savename($url) - changed from \$$price to \$$1 \n\n"; } print CONTACTS2 "$savename###$url###$1\n"; } elsif ( $searchString2 ne "" ) { if( /$searchString2/ ) { $match = $1; # check if price is the same if( $1 ne $price ) { # price changed, so add to "changes" list $changes .= "$savename($url) - changed from \$$price to \$$1 \n\n"; } print CONTACTS2 "$savename###$url###$1\n"; }else { print CONTACTS2 "$savename###$url###$price\n"; $changes .= "No match on $savename($url)\n\n"; } }else { print CONTACTS2 "$savename###$url###$price\n"; $changes .= "No match on $savename($url)\n\n"; } } close( CONTACTS ); close( CONTACTS2); # copy new list onto old one to ensure things are the same next time system( "cp $readPath.$companyName $readPath$companyName" ); # if prices changed, email if( $changes ne "" ) { system ("date"); print "$companyName:\n$changes"; $smtp = Net::SMTP->new('localhost'); # connect to an SMTP server $smtp->mail( $email ); if ($ccemail ne "") { $smtp->to($email, $ccemail); }else { $smtp->to($email); } $smtp->data(); # Send the header. $smtp->datasend("To: $email \n"); $smtp->datasend("From: $email\n"); $smtp->datasend("Subject: $companyName Price Changes\n"); $smtp->datasend("\n"); # Send the body. # $smtp->datasend("$changes\n"); $smtp->dataend(); $smtp->quit; }else { system("date"); print "$companyName: No change\n"; } # End Of File