Created
October 7, 2010 12:48
-
-
Save JGaudette/615049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Net::Amazon; | |
use Net::Amazon::Request::Wishlist; | |
use DBI; | |
use Product; | |
sub createRecord{ | |
my $rec = shift; | |
print "creating record for: " . $rec->getAsin() . "\n"; | |
my $db='amazon'; | |
my $host="localhost"; | |
my $uid="USERNAME"; | |
my $passwd="PASSWORD"; | |
my $conn="dbi:mysql:$db:$host"; | |
my $asin = $rec->getAsin(); | |
my $name = $rec->getName(); | |
my $desc = ""; | |
# quotes will ruin our query, replace with underscore | |
$name =~ s/'//g; | |
my $dbh = DBI->connect($conn,$userid,$passwd); | |
my $query = "insert into products(asin,name,description) values('$asin','$name','$desc')"; | |
my $sth = $dbh->prepare($query); | |
$sth->execute(); | |
} | |
my $ua = Net::Amazon->new(token=>'YOUR_AMAZON_TOKEN'); | |
my $req = Net::Amazon::Request::Wishlist->new(wishlist=>'YOUR_WISHLIST_ID'); | |
my @products; | |
my @wishlist; | |
my $db='amazon'; | |
my $host="localhost"; | |
my $uid="USERNAME"; | |
my $passwd="YOUR_PASSWORD"; | |
my $conn="dbi:mysql:$db:$host"; | |
my $dbh = DBI->connect($conn,$userid,$passwd); | |
my $query = "select asin,name,description from products"; | |
my $sth = $dbh->prepare($query); | |
$sth->execute(); | |
$sth->bind_columns(\$asin, \$name, \$description); | |
while($sth->fetch()){ | |
#print "found: $asin | $name | $description\n"; | |
push(@products, Product->new($asin, $name, $description)); | |
} | |
my $resp = $ua->request($req); | |
foreach my $item ($resp->properties){ | |
push(@wishlist, Product->new($item->ASIN(), $item->ProductName(),)); | |
} | |
#foreach(@products){ | |
# print "Found a product: " . $_->getAsin() . "\n"; | |
#} | |
foreach my $wish (@wishlist){ | |
#print "Found a wishlist: " . $_->getAsin() . "\n"; | |
my $flag = 0; | |
foreach my $prod (@products){ | |
if($wish->getAsin() eq $prod->getAsin()){ | |
$flag = 1; | |
} | |
} | |
if($flag == 0){ | |
createRecord($wish); | |
} | |
} | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment