pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit f2af491357d273f6b21c7a94297573a1bbe7131b
parent 52e7d50988374b8f9a6e19ba382bfed601b0f332
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Mon,  3 Nov 2014 20:07:30 -0700

product_scraper: prepare query outside main loops

Diffstat:
Mproduct_scraper.pl | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/product_scraper.pl b/product_scraper.pl @@ -40,6 +40,8 @@ $email .= "*** $vendor ***\n\n"; $email .= "type scraped total new time\n"; $email .= "------------ ------- ----- --- ----\n"; +my $product_sth = $dbh->prepare("select * from products where part_num = ?"); + my @new = (); for (keys %product_map) { @@ -102,10 +104,8 @@ for (keys %product_map) { ($part_num) = ($part_num =~ m/Part #: (.*)\r/); next if (not_defined($part_num, "part number", $product_dom)); - my $query = "select * from products where part_num = ?"; - my $sth = $dbh->prepare($query); - $sth->execute($part_num); - if ($sth->fetchrow_arrayref()) { + $product_sth->execute($part_num); + if ($product_sth->fetchrow_arrayref()) { $dbh->do("update products set last_seen = ? where part_num = ?", undef, time, $part_num); # also update description, manufacturer here? @@ -132,6 +132,7 @@ for (keys %product_map) { $email .= "\nNew products:\n" if (@new); $email .= "- ($_->[0]) $_->[1] $_->[2] $_->[3]\n" for (@new); +$product_sth->finish(); $dbh->disconnect(); my $date = strftime "%d/%m/%Y", localtime;