commit 7880b232a06efc76b3de8676a555944e0de87f06
parent a4e29c99d5075bd6c896e08dcb58390bd4eb3fff
Author: Kyle R W Milz <kyle@getaddrinfo.net>
Date: Mon, 11 Aug 2014 21:28:27 -0600
price_scraper: get products from database
Diffstat:
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/price_scraper.pl b/price_scraper.pl
@@ -5,6 +5,7 @@ use warnings;
use Config::Grammar;
use Data::Dumper;
+use DBI;
use File::Basename;
use Getopt::Std;
use JSON;
@@ -53,6 +54,12 @@ elsif (-e "price_scraper.cfg") {
my $cfg = $parser->parse($cfg_file) or die "ERROR: $parser->{err}\n";
+my $dbh = DBI->connect(
+ "dbi:SQLite:dbname=pricechart.db",
+ "",
+ "",
+ { RaiseError => 1 },) or die $DBI::errstr;
+
if ($args{v}) {
# Disable buffering on STDOUT
$| = 1;
@@ -94,10 +101,16 @@ sub make_parts_list
sub scrape_vendors
{
- my $part_no = shift;
my $time_start = time;
my @prices;
+ my $sth = $dbh->prepare("select part_num from products");
+ $sth->execute();
+ my @results = $sth->fetchrow_array();
+ # sequentially pick one product every hour
+ my $index = (time / 3600) % scalar(@results);
+ my $part_no = $results[$index];
+
print strftime '%b %e %Y %H:%M ', localtime;
printf '%-10s [', $part_no;