commit 1860b3e1ea666b85e7f2aef3753aa2d81cd88593
parent 5bc28dcc231fd48c15ccd5c320262f6316eb41c7
Author: kyle <kyle@getaddrinfo.net>
Date:   Sun,  6 Mar 2016 15:07:00 -0700
memexp: some minor fixes
Diffstat:
2 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/PS/MemoryExpress.pm b/PS/MemoryExpress.pm
@@ -32,9 +32,6 @@ sub new {
 	my $self = {
 		color => "#56B849",
 		url => "http://www.memoryexpress.com/Search/Products?Search=",
-		title => ".ProductTitle",
-		reg_tag => ".PIV_Price",
-		sale_tag => ".PIV_PriceSale",
 		ua => PS::UserAgent->new(),
 		db => PS::Database->new()
 	};
@@ -49,13 +46,12 @@ sub new {
 
 # Creates the URL search string.
 sub create_search {
-	my ($self, $part_num) = @_;
+	my ($self, $manufacturer, $part_num) = @_;
 
 	# As learned in the Seagate ST8000AS0002 case searching for manufacturer
 	# concatenated to part num will hide valid search results.
 	# Instead search only for part number. We'll have to deal with thumbnail
 	# view return vs a full page product.
-
 	return $self->{url} . uri_escape($part_num);
 }
 
@@ -106,7 +102,7 @@ sub find_product_page {
 	my $uri = $resp->base;
 	if ($uri =~ /.*\/Products\/.*/) {
 		# We landed on the product page directly, great.
-		return $resp;
+		return ($resp);
 	}
 	elsif ($uri =~ /.*\/Search\/.*/) {
 		# We landed on the search page.
@@ -133,22 +129,23 @@ sub find_product_page {
 	}
 }
 
-sub scrape_all {
+sub scrape {
 	my ($self, $manufacturer, $part_num) = @_;
 	my $ua = $self->{ua};
 
-	my $search = $self->create_search($part_num);
+	my $search = $self->create_search($manufacturer, $part_num);
 	return unless ($search);
 
 	my $resp = $ua->get_dom($search);
 	return unless ($resp->is_success);
 
 	# Searching can sometimes take you to different places
-	my $resp = $self->find_product_page($resp);
+	($resp) = $self->find_product_page($resp);
 	return unless ($resp);
 
-	my $part_num = $self->scrape_part_num($resp);
-	my $price = $self->scrape_price($resp);
+	# my $part_num = $self->scrape_part_num($resp);
+	my ($price) = $self->scrape_price($resp);
+	my $desc = $self->scrape_description($resp);
 
 	my $sql = qq{insert into prices(date, manufacturer, part_num, retailer,
 	price, duration) values (?, ?, ?, ?, ?, ?)};
diff --git a/t/memory_express.t b/t/memory_express.t
@@ -4,7 +4,7 @@ use PS::MemoryExpress;
 use Log::Log4perl qw(:easy);
 use Test;
 
-BEGIN { plan tests => 18 }
+BEGIN { plan tests => 17 }
 
 Log::Log4perl->easy_init($INFO);
 
@@ -13,16 +13,12 @@ my $me = PS::MemoryExpress->new();
 
 # Search for a Seagate hard drive I know about
 #
-my $search_url = $me->create_search("ST8000AS0002");
+my $search_url = $me->create_search("Seagate", "ST8000AS0002");
 my $resp = $ua->get_dom($search_url);
 ok($resp->is_success);
 
-# Check the returned URI is the product page directly
-my $uri = $resp->base;
-ok($uri =~ /.*\/Products\/.*/);
-
 # Check that the object is working
-my $obj_resp = $me->find_product_page($resp);
+my ($obj_resp) = $me->find_product_page($resp);
 ok($obj_resp->base, $resp->base);
 
 # Make sure the part number we scrape is correct
@@ -42,13 +38,12 @@ ok($descr, "8TB Archive HDD, SATA III w/ 128MB Cache");
 
 # Search for something I know has multiple results
 #
-my $search_url = $me->create_search("ST8000");
+my $search_url = $me->create_search("Seagate", "ST8000");
 $resp = $ua->get_dom($search_url);
 ok($resp->is_success);
 
 # The returned URI should have been the search results page
-$uri = $resp->base;
-ok($uri =~ /.*\/Search\/.*/);
+ok($resp->base =~ /.*\/Search\/.*/);
 
 # Searching for the above product yields two results
 my ($obj_resp, @others) = $me->find_product_page($resp);
@@ -59,12 +54,11 @@ ok($obj_resp->is_success);
 
 # Search for something that returns 0 results
 #
-my $search_url = $me->create_search("some nonexistent product here");
+my $search_url = $me->create_search("", "some nonexistent product here");
 $resp = $ua->get_dom($search_url);
 ok($resp->is_success);
 
-$uri = $resp->base;
-ok($uri =~ /.*\/Search\/.*/);
+ok($resp->base =~ /.*\/Search\/.*/);
 
 my ($obj_resp) = $me->find_product_page($resp);
 ok( !defined $obj_resp );