App-BarnesNoble-WishListMinder
view release on metacpan or search on metacpan
lib/App/BarnesNoble/WishListMinder.pm view on Meta::CPAN
}
#=====================================================================
has mech => qw(is lazy);
sub _build_mech {
require WWW::Mechanize;
WWW::Mechanize->new(
autocheck => 1,
cookie_jar => { file => shift->cookie_file, autosave => 1 },
);
} # end _build_mech
has dir => qw(is lazy);
sub _build_dir {
require File::HomeDir;
File::HomeDir->VERSION(0.93); # my_dist_data
path(File::HomeDir->my_dist_data('App-BarnesNoble-WishListMinder',
{ create => 1 })
or die "Can't determine data directory");
} # end _build_dir
has config_file => qw(is lazy);
sub _build_config_file {
shift->dir->child('config.ini');
} # end _build_config_file
has config => qw(is lazy);
sub _build_config {
my $self = shift;
require Config::Tiny;
my $fn = $self->config_file;
Config::Tiny->read("$fn", 'utf8')
or die "Unable to read $fn: " . Config::Tiny->errstr;
} # end _build_config
has cookie_file => qw(is lazy);
sub _build_cookie_file {
shift->dir->child('cookies.txt');
} # end _build_cookie_file
has db_file => qw(is lazy);
sub _build_db_file {
shift->dir->child('wishlist.sqlite');
} # end _build_db_file
has dbh => qw(is lazy predicate 1 clearer _clear_dbh);
sub _build_dbh {
my $self = shift;
require DBI;
DBI->VERSION(1.38); # last_insert_id
my $fn = $self->db_file;
my $exists = $fn->exists;
my $dbh = DBI->connect("dbi:SQLite:dbname=$fn","","",
{ AutoCommit => 0, PrintError => 0, RaiseError => 1,
sqlite_unicode => 1 });
$self->create_database_schema($dbh) unless $exists;
$dbh;
} # end _build_dbh
sub close_dbh
{
my $self = shift;
if ($self->has_dbh) {
my $dbh = $self->dbh;
$dbh->rollback;
$dbh->disconnect;
$self->_clear_dbh;
}
} # end close_dbh
has scraper => qw(is lazy);
sub _build_scraper {
require Web::Scraper::BarnesNoble::WishList;
Web::Scraper::BarnesNoble::WishList::bn_scraper();
} # end _build_scraper
has updates => qw(is ro default) => sub { {} };
#---------------------------------------------------------------------
sub configure
{
my ($self) = @_;
my $config_file = $self->config_file;
say "Your config file is:\n $config_file";
unless ($config_file->is_file) {
die "$config_file is a directory!\n" if $config_file->is_dir;
$config_file->spew_utf8(<<'END CONFIG');
; -*-conf-windows-*-
; Your credentials for logging in to the Barnes & Noble website go here:
email = YOUR EMAIL HERE
password = YOUR PASSWORD HERE
; If you want the Price Drop Alert emails to go to a different address,
; uncomment the next line and set the email address.
;report = EMAIL ADDRESS FOR ALERTS
; Next, you need one or more wishlists to monitor.
; Each wishlist must have a unique name in [brackets].
[My Wishlist]
wishlist = WISHLIST URL HERE
END CONFIG
say "\nYou need to replace the ALL CAPS placeholders with the correct values.";
}
if (my $editor = $ENV{VISUAL} || $ENV{EDITOR}) {
require Text::ParseWords;
system(Text::ParseWords::shellwords($editor), "$config_file");
( run in 1.485 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )