commit 27405e3193a67649e7773422b7a7bee3345902a6
parent ad63d5afb068d3e790083e7ae52862e90e22e930
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Thu, 6 Nov 2014 22:31:20 -0700
price_scraper: simplify picking product to update
Diffstat:
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/price_scraper.pl b/price_scraper.pl
@@ -8,22 +8,15 @@ use shared;
my $ua = get_ua();
-my $part_num;
-if ($args{p}) {
- $part_num = $args{p};
-}
-else {
- my $cutoff = time - (30 * 24 * 60 * 60);
- my $results = $dbh->selectrow_arrayref("select part_num from products " .
- "where last_seen > $cutoff order by last_scraped asc");
- if (! @$results) {
- print "Product table empty, run product_scraper.pl\n";
- exit;
- }
- $part_num = $results->[0];
- $dbh->do("update products set last_scraped = ? where part_num = ?",
- undef, time, $part_num);
-}
+# pick the oldest product
+my $cutoff = time - (30 * 24 * 60 * 60);
+my $sql = "select part_num from products where last_seen > $cutoff " .
+ "order by last_scraped asc";
+my ($part_num) = $dbh->selectrow_array($sql);
+exit unless (defined $part_num);
+
+$dbh->do("update products set last_scraped = ? where part_num = ?",
+ undef, time, $part_num);
$dbh->do("create table if not exists prices(" .
"date int not null, " .