From 6663fb44cb7195480d89415f5afe6b37f5ed39b9 Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 19 Apr 2004 00:04:17 +0000 Subject: [PATCH] implement ordering bom --- farnell/farnell-find | 52 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/farnell/farnell-find b/farnell/farnell-find index 1ab15df..5c87495 100755 --- a/farnell/farnell-find +++ b/farnell/farnell-find @@ -11,6 +11,8 @@ # then will prompt and read a line from tty. # ./farnell-find [] bom ... # Processes input files and produces BOM parts list. +# ./farnell-find [] order-bom ... +# Processes input files and adds BOM parts to cart. # # Options: # -S @@ -224,6 +226,7 @@ sub cart_add (@) { my ($i, $url, $item, $qty, @submit, $request, $response); my ($page_output); local ($_); + need_jsessionid(); $url= "$urlbase/jsp/op/shoppingbasket.jsp;jsessionid=$jsessionid"; get_useragent(); $response= $useragent->get($url); @@ -399,11 +402,12 @@ sub iteminstanceprint ($) { $ii->{Use}); } -sub analyse_spec () { +sub analyse_spec ($) { + my ($op) = @_; my ($part,$pd,$try,@rhs,$sp,$circuit,$iteratable,$count,$pe,$use); my ($item,$totalqty,$ii,$bi,$toorder,$price,$total,$notechar,$desc); my ($avail,%avail,$desclen,$why,$suppress,%suppress,$pi); - my ($iteminstance); + my ($iteminstance,@orderlist); $desclen= 42; foreach $part (sort keys %partdef) { $item= $partdef{$part}; @@ -492,6 +496,7 @@ sub analyse_spec () { $show{$item}{Info}= ''; $total += $price; $show{$item}{Price}= $price; + $show{$item}{ToOrder}= $toorder; foreach $desc (@{ $itemdesc{$item} }) { $show{$item}{Info} .= sprintf("%*s %s\n", @@ -502,10 +507,21 @@ sub analyse_spec () { $show{$item}{Info} .= iteminstanceprint($ii); } } + if ($op eq 'order-bom') { + dump_warnerrs(); + } foreach $item (sort { itemsortmap($a) cmp itemsortmap($b); } keys %show) { - print $show{$item}{Head}, $show{$item}{Info}, "\n" - or die $!; + if ($op eq 'order-bom') { + push @orderlist, $item, $show{$item}{ToOrder}; + } else { + print $show{$item}{Head}, $show{$item}{Info}, "\n" + or die $!; + } + } + if ($op eq 'order-bom') { + cart_add(@orderlist); + die; } printf("%*s %11s %-*s %6.2f\n", (5+1), 'TOTAL', @@ -631,6 +647,20 @@ sub is_jsessionid ($) { return $1; } +sub need_jsessionid () { + local ($_); + my ($newjsid); + return if defined $jsessionid; + open TTY, "+< /dev/tty" or die $!; + select((select(TTY), $|=1)[0]); + print TTY "URL or jsessionid: " or die $!; + $_= ; TTY->error and die $!; + length or die; + $newjsid= is_jsessionid($_); + defined $newjsid or die; + $jsessionid= $newjsid; +} + sub main () { my ($op); my ($item, $a); @@ -673,23 +703,13 @@ sub main () { } die $! if STDIN->error; } - if (!defined $jsessionid) { - open TTY, "+< /dev/tty" or die $!; - select((select(TTY), $|=1)[0]); - print TTY "URL or jsessionid: " or die $!; - $_= ; TTY->error and die $!; - length or die; - $newjsid= is_jsessionid($_); - defined $newjsid or die; - $jsessionid= $newjsid; - } cart_add(@orderlist); - } elsif ($op eq 'bom') { + } elsif ($op eq 'bom' || $op eq 'order-bom') { my ($filename); foreach $filename (@ARGV) { read_spec($filename); } - analyse_spec(); + analyse_spec($op); exit !!@fault; } else { die; -- 2.30.2