pricecharts

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

commit dfacfef3a4ee892f2a232cc5d6ae0bf4a1c9723f
parent 5ad460d6039483f0e6a3d32c835c588960e43866
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Wed,  4 Feb 2015 00:17:00 -0700

PriceChart: get_dbh now takes a second dir arg

Diffstat:
MPriceChart.pm | 7++++---
Mgen_svg.pl | 4+++-
Mprice_scraper.pl | 2+-
Mproduct_scraper.pl | 2+-
4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/PriceChart.pm b/PriceChart.pm @@ -16,6 +16,7 @@ sub get_config 'user_agent', 'email', 'smtp', + "db" ], }, http => { @@ -49,9 +50,8 @@ sub get_config sub get_dbh { - # XXX: needs to be changed in production! - my $db_dir = shift || "/var/www/db"; - # my $db_dir = "./"; + my $cfg = shift; + my $db_dir = shift || $cfg->{"db"}; mkdir $db_dir; my $dbh = DBI->connect( @@ -60,6 +60,7 @@ sub get_dbh "", { RaiseError => 1 } ) or die $DBI::errstr; + return $dbh; } diff --git a/gen_svg.pl b/gen_svg.pl @@ -3,6 +3,7 @@ use strict; use warnings; +use Config::Grammar; use Getopt::Std; use SVG; use POSIX; @@ -15,7 +16,8 @@ getopts("v", \%args); $| = 1 if ($args{v}); # my $log = get_log("gen_svg"); -my $dbh = get_dbh(); +my $cfg = get_config(); +my $dbh = get_dbh($cfg->{"general"}); my $svg_dir = "/var/www/htdocs/pricechart/svg"; mkdir $svg_dir; diff --git a/price_scraper.pl b/price_scraper.pl @@ -21,7 +21,7 @@ $| = 1 if ($args{v}); my $log = get_log("scrapes", $args{v}); my $cfg = get_config(); my $ua = get_ua($cfg->{"general"}); -my $dbh = get_dbh(); +my $dbh = get_dbh($cfg->{"general"}); # allow products to go out of stock. if we haven't seen them for > 30 days # chances are retailers aren't carrying them anymore diff --git a/product_scraper.pl b/product_scraper.pl @@ -19,7 +19,7 @@ $| = 1 if ($args{v}); my $cfg = get_config(); my $ua = get_ua($cfg->{"general"}); -my $dbh = get_dbh(); +my $dbh = get_dbh($cfg->{"general"}); srand; $dbh->do("create table if not exists products(" .