chiark / gitweb /
alarming - it hides your order in your browser state
authorian <ian>
Sun, 18 Apr 2004 20:37:13 +0000 (20:37 +0000)
committerian <ian>
Sun, 18 Apr 2004 20:37:13 +0000 (20:37 +0000)
farnell/farnell-find

index da3871b81c37a31f1c98560b2be7fe8f35a30828..81c2ca69d1842c866939176bcadd052c13880748 100755 (executable)
@@ -70,6 +70,7 @@ use IO::Handle;
 use IO::File;
 use LWP::UserAgent;
 use HTTP::Request;
+use HTTP::Request::Common;
 use HTTP::Response;
 
 our(@warn);
@@ -131,6 +132,7 @@ our($item_re)= '\d{3}\-\d{3,7}';
 
 our(%stockmap)= ('In Stock' => 'Y',
                 'Awaiting Delivery' => 'A');
+our($urlbase)= 'http://uk.farnell.com';
 
 sub get_useragent () {
     my ($whoami,$mailname);
@@ -141,13 +143,18 @@ sub get_useragent () {
     $useragent= new LWP::UserAgent(env_proxy => 1, keep_alive =>1);
 }
 
+sub check_response ($$) {
+    my ($response,$url) = @_;
+    $response->is_success or die "$url ".$response->as_string." ?";
+}
+
 sub by_item ($;$) {
     my ($itemcode,$why) = @_;
     # looks up $itemcode (ddd-d...) at Farnell and returns
     # cat hash ref
     local ($_);
     my ($chr,$shortcode,$sc2,$url,$price);
-    $url= 'http://uk.farnell.com/jsp/catalog/viewproductdetails.jsp?prodId=';
+    $url= "$urlbase/jsp/catalog/viewproductdetails.jsp?prodId=";
     $itemcode =~ m/^(\d\d\d)\-(\d{3,7})$/ or die "$itemcode ?";
     $chr->{Item}= $itemcode;
     $chr->{Shortcode}= $1.$2;
@@ -155,10 +162,8 @@ sub by_item ($;$) {
     if (!-f "farn.$itemcode") {
        my ($response);
        get_useragent();
-       print STDERR "got ua... $url\n";
        $response= $useragent->get($url);
-       print STDERR "got response... $response\n";
-       $response->is_success or die "$url ".$response->as_string." ?";
+       check_response($response, $url);
        $_= $response->content;
        open N, ">tmp.farn.$itemcode" or die $!;
        print N or die $!;
@@ -211,12 +216,55 @@ sub snarf ($;$) {
 
 sub cart_add (@) {
     my (@orderlist) = @_;
-    my ($i);
+    my ($i, $url, $item, $qty, @submit, $request, $response);
+    $url= "$urlbase/jsp/op/shoppingbasket.jsp;jsessionid=$jsessionid".
+       "?_DARGS=/jsp/home/quickbuycontent.jsp";
+    @submit= (
+#_DARGS => "/jsp/home/quickbuycontent.jsp",
+
+'_dyncharset' => 'ASCII',
+#'/pf/commerce/PFCartHandler.setOrderSuccessURL' => '/jsp/op/shoppingbasket.jsp',
+#'_D:/pf/commerce/PFCartHandler.setOrderSuccessURL' => ' ',
+#'/pf/commerce/PFCartHandler.setOrderErrorURL' => '/jsp/op/shoppingbasket.jsp',
+#'_D:/pf/commerce/PFCartHandler.setOrderErrorURL' => ' ',
+'/pf/commerce/PFCartHandler.addLinesSuccessURL' => '/jsp/op/shoppingbasket.jsp',
+'_D:/pf/commerce/PFCartHandler.addLinesSuccessURL' => ' ',
+#'/pf/commerce/PFCartHandler.moveToPurchaseInfoErrorURL' => '/jsp/op/shoppingbasket.jsp',
+#'_D:/pf/commerce/PFCartHandler.moveToPurchaseInfoErrorURL' => ' ',
+#'/pf/commerce/PFCartHandler.addPotentialProductsSuccessURL' => '/jsp/op/shoppingbasket.jsp',
+#'_D:/pf/commerce/PFCartHandler.addPotentialProductsSuccessURL' => ' ',
+#'/pf/commerce/PFCartHandler.addPotentialProductsErrorURL' => '/jsp/op/shoppingbasket.jsp',
+#'_D:/pf/commerce/PFCartHandler.addPotentialProductsErrorURL' => ' ',
+#'/pf/commerce/PFCartHandler.fowardOrderSuccessURL' => '/jsp/op/forwardmultistageorder.jsp',
+#'_D:/pf/commerce/PFCartHandler.fowardOrderSuccessURL' => ' ',
+#'/pf/commerce/PFCartHandler.moveToPurchaseInfoSuccessURL' => 'https://secure.farnell.com/jsp/op/shipping.jsp;jsessionid=UPTT45ICG5DERQFIAEXSFE4AVAAS4IV3',
+#'_D:/pf/commerce/PFCartHandler.moveToPurchaseInfoSuccessURL' => ' ',
+'/pf/commerce/PFCartHandler.setOrderByCommerceId.x' => '0',
+'/pf/commerce/PFCartHandler.setOrderByCommerceId.y' => '0',
+'_D:/pf/commerce/PFCartHandler.setOrderByCommerceId' => ' ',
+'_DARGS' => '/jsp/home/quickbuycontent.jsp',
+
+
+             );
     while (@orderlist) {
-       for ($i=0; $i<5; $i++) {
-           # fixme finish this
-       }
+       ($item, $qty, @orderlist) = @orderlist;
+       push @submit,
+       'k1', $item,
+       '_D:k1', ' ',
+       'k3', $qty,
+       '_D:k3', ' ';
     }
+    get_useragent();
+print STDERR "url $url; @submit.\n";
+    $request= POST $url, \@submit;
+    $useragent->prepare_request($request);
+printf STDERR "request %s.\n", $request->as_string;
+    $response= $useragent->request($request);
+    check_response($response,$url);
+    open N, ">tmp.farn.basket.html" or die $!;
+    print N $response->content or die $!;
+    close N or die $!;
+    exec 'w3m','./tmp.farn.basket.html'; die $!;
 }
 
 sub read_spec ($) {
@@ -544,29 +592,33 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
     }
 }
 
-if (@ARGV==1 && $ARGV[0] =~ m/^\d\d\d\-/) {
-    my ($chr, $k);
-    $chr= by_item($ARGV[0]);
-    dump_warnerrs();
-    foreach $k (sort keys %$chr) {
-       printf "%-20s %s\n", $k, $chr->{$k} or die $!;
-    }
-} elsif (@ARGV > 1 && (@ARGV % 1) && $ARGV[0] =~ m/^\d\d\d\-/) {
-    my (@orderlist,$item,$qty);
-    $jsessionid= pop @ARGV;
-    if ($jsessionid =~ m/\;jsessionid=([0-9A-Z]+)\b/) {
-       $jsessionid= $1;
-    } elsif ($jsessionid =~ m/^([0-9A-Z]+)$/) {
+if (@ARGV && $ARGV[0] =~ m/^\d\d\d\-/) {
+    if (@ARGV==1) {
+       my ($chr, $k);
+       $chr= by_item($ARGV[0]);
+       dump_warnerrs();
+       foreach $k (sort keys %$chr) {
+           printf "%-20s %s\n", $k, $chr->{$k} or die $!;
+       }
+    } elsif (@ARGV > 1 && (@ARGV % 2)) {
+       my (@orderlist,$item,$qty);
+       $jsessionid= pop @ARGV;
+       if ($jsessionid =~ m/\;jsessionid=([0-9A-Z]+)\b/) {
+           $jsessionid= $1;
+       } elsif ($jsessionid =~ m/^([0-9A-Z]+)$/) {
+       } else {
+           die "bad jsessionid\n";
+       }
+       while (@ARGV) {
+           ($item,$qty,@ARGV) = @ARGV;
+           $item =~ m/^$item_re$/ or die "$item ?";
+           $qty =~ m/^[1-9]\d{0,5}$/ or die "$qty ?";
+           push @orderlist, $item, $qty;
+       }
+       cart_add(@orderlist);
     } else {
-       die "bad jsessionid\n";
-    }
-    while (@ARGV) {
-       ($item,$qty,@ARGV) = @ARGV;
-       $item =~ m/^$item_re$/ or die "$item ?";
-       $qty =~ m/^[1-9]\d{0,5}$/ or die "$qty ?";
-       push @orderlist, { Item => $item, Qty => $qty };
+       die;
     }
-    cart_add(@orderlist);
 } elsif (@ARGV) { 
     my ($filename);
     foreach $filename (@ARGV) {