Skip to content

Instantly share code, notes, and snippets.

@typester
Created January 20, 2011 01:20
Show Gist options
  • Save typester/787232 to your computer and use it in GitHub Desktop.
Save typester/787232 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use WWW::Mechanize;
use Cocoa::EventLoop;
use Cocoa::Growl ':all';
GetOptions(
\my %options,
qw/help wait=i/
);
pod2usage(0) if $options{help};
my $asin = $ARGV[0] or die 'require ASIN';
die 'growl is not installed' unless growl_installed;
die 'growl is not runnning' unless growl_running;
growl_register(
app => 'Amazon checker',
notifications => ['Default'],
);
my $m = WWW::Mechanize->new( stack_depth => 1 );
$m->agent_alias('Windows IE 6');
my $u = "http://www.amazon.co.jp/dp/${asin}";
my $check; $check = sub {
$m->get($u);
if ($m->content =~ /addToCartSpan/) {
growl_notify(
name => 'Default',
title => 'ktkr!',
description => $u,
on_click => sub {
system 'open', $u;
},
);
}
Cocoa::EventLoop->timer(
after => $options{wait} || 60,
cb => $check,
);
};
$check->();
Cocoa::EventLoop->run;
__END__
=head1 NAME
check_amazon.pl - check amazon item availability
=head1 SYNOPSIS
check_amazon.pl [OPTIONS...] ASIN
options:
-h --help show this help
-w --wait polling interval (default 60)
=head1 DESCRIPTION
check specified amazon item and show growl notification if the item is available.
=head1 AUTHOR
Daisuke Murase <typester@cpan.org>
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment