pricecharts

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

commit d8e40ca538435ee63cd5fd3b2ebadb1d666cf674
parent 4f84b9bdc9a230240718288d8458969089751846
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Sun, 12 Oct 2014 22:14:48 -0600

rename Shared.pm -> shared.pm

Diffstat:
DShared.pm | 70----------------------------------------------------------------------
Mprice_scraper.pl | 3++-
Mproduct_scraper.pl | 3++-
Ashared.pm | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 72 deletions(-)

diff --git a/Shared.pm b/Shared.pm @@ -1,70 +0,0 @@ -#!/usr/bin/env perl - -package Shared; -use Config::Grammar; -use Exporter; - -@ISA = ("Exporter"); -@EXPORT = ("get_dom", "get_config", "get_dbh"); - -sub get_dom -{ - my $url = shift; - my $ua = shift; - - my $resp = $ua->get($url); - if (! $resp->is_success) { - print "getting $url failed: " . $resp->status_line . "\n"; - return undef; - } - return HTML::Grabber->new(html => $resp->decoded_content); -} - -sub get_config -{ - my $cfg_file = shift; - if (!defined $cfg_file) { - if (-e "pricechart.cfg") { - $cfg_file = "pricechart.cfg"; - } else { - $cfg_file = "/etc/pricechart.cfg"; - } - } - - my $parser = Config::Grammar->new({ - _sections => ['vendors', 'general'], - vendors => { - # vendor regular expression - _sections => ['/[A-Za-z ]+/'], - '/[A-Za-z ]+/' => { - _vars => ['search_uri', 'reg_price', 'sale_price', 'color'], - }, - }, - general => { - _vars => [ - 'http_path', - 'log_file', - 'user_agent', - 'email', - 'smtp', - 'db_file' - ], - }, - }); - - return $parser->parse($cfg_file) or die "ERROR: $parser->{err}\n"; -} - -sub get_dbh -{ - my $cfg = shift; - - my $dbh = DBI->connect( - "dbi:SQLite:dbname=$cfg->{general}{db_file}", - "", - "", - { RaiseError => 1 },) or die $DBI::errstr; - return $dbh; -} - -1; diff --git a/price_scraper.pl b/price_scraper.pl @@ -8,9 +8,10 @@ use DBI; use Getopt::Std; use HTML::Grabber; use LWP::Simple; -use Shared; use POSIX; +use shared; + my %args; getopts('f:np:v', \%args); diff --git a/product_scraper.pl b/product_scraper.pl @@ -10,9 +10,10 @@ use Email::Send; use Getopt::Std; use HTML::Grabber; use LWP::Simple; -use Shared; use POSIX; +use shared; + my %args; getopts("vf:", \%args); diff --git a/shared.pm b/shared.pm @@ -0,0 +1,70 @@ +#!/usr/bin/env perl + +package shared; +use Config::Grammar; +use Exporter; + +@ISA = ("Exporter"); +@EXPORT = ("get_dom", "get_config", "get_dbh"); + +sub get_dom +{ + my $url = shift; + my $ua = shift; + + my $resp = $ua->get($url); + if (! $resp->is_success) { + print "getting $url failed: " . $resp->status_line . "\n"; + return undef; + } + return HTML::Grabber->new(html => $resp->decoded_content); +} + +sub get_config +{ + my $cfg_file = shift; + if (!defined $cfg_file) { + if (-e "pricechart.cfg") { + $cfg_file = "pricechart.cfg"; + } else { + $cfg_file = "/etc/pricechart.cfg"; + } + } + + my $parser = Config::Grammar->new({ + _sections => ['vendors', 'general'], + vendors => { + # vendor regular expression + _sections => ['/[A-Za-z ]+/'], + '/[A-Za-z ]+/' => { + _vars => ['search_uri', 'reg_price', 'sale_price', 'color'], + }, + }, + general => { + _vars => [ + 'http_path', + 'log_file', + 'user_agent', + 'email', + 'smtp', + 'db_file' + ], + }, + }); + + return $parser->parse($cfg_file) or die "ERROR: $parser->{err}\n"; +} + +sub get_dbh +{ + my $cfg = shift; + + my $dbh = DBI->connect( + "dbi:SQLite:dbname=$cfg->{general}{db_file}", + "", + "", + { RaiseError => 1 },) or die $DBI::errstr; + return $dbh; +} + +1;