From 22bd4cbd5ff38bb1f07c362d63254ed162b83398 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 8 Apr 2004 00:54:59 +0000 Subject: [PATCH] can find things --- .cvsignore | 1 + farnell/farnell-find | 174 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 161 insertions(+), 14 deletions(-) diff --git a/.cvsignore b/.cvsignore index fa3989b..08aaf5d 100644 --- a/.cvsignore +++ b/.cvsignore @@ -10,3 +10,4 @@ testjoin *,*.gnuplot-cmd *,gnuplot-fifo *.gnuplots.sh +farn.* diff --git a/farnell/farnell-find b/farnell/farnell-find index 9a5ceab..038713f 100755 --- a/farnell/farnell-find +++ b/farnell/farnell-find @@ -1,11 +1,37 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w + +use strict; + +our(@warn); +our(@fault); +our(%pkinddesc); # $pkinddesc{'a b c'} => 'y' after `a b c ? = y' + +our(%parts); +# $parts{"$sect/$sper"}[]{Part} +# $parts{"$sect/$sper"}[]{Qty} +# $parts{"$sect/$sper"}[]{Desc} + +our(%partdef); +# $partdef{"part name"}{Item} +# $partdef{"part name"}{Desc} + +our(%count); +# $count{"$sper"} is number of times sper is instantiated +# (no syntax for specifying this atm) + +our(%iteminstances); +# @{ $iteminstances{$item} } one entry for every sect/sper which has it +# $iteminstances{$item}[]{Desc} +# $iteminstances{$item}[]{Qty} +# $iteminstances{$item}[]{SectPer} +# $iteminstances{$item}[]{Mult} number in this sect/sper sub by_item ($) { my ($itemcode) = @_; # looks up $itemcode (ddd-d...) at Farnell and returns # cat hash ref local ($_); - my ($chr,$shortcode,$sc2,$url); + my ($chr,$shortcode,$sc2,$url,$price); $url= 'http://uk.farnell.com/jsp/catalog/viewproductdetails.jsp?prodId='; $itemcode =~ m/^(\d\d\d)\-(\d{3,7})$/ or die; $chr->{Item}= $itemcode; @@ -18,41 +44,159 @@ sub by_item ($) { unlink "tmp.farnerr.$itemcode"; } $_= `cat farn.$itemcode`; $? and die $?; - s/[^\n\t\x20-\x7e]/\?/g; - $sc2= snarf('Order Code / Sku'); - die "wrong results $snarf ?" unless $sc2 eq $chr->{Shortcode}; + s/[^\n\t\x20-\x7e\£]/\?/g; + if (!eval { + $sc2= snarf('Order Code / Sku'); + die "wrong results $sc2 ?\n" unless $sc2 eq $chr->{Shortcode}; + 1; + }) { + $@ =~ s/\n$//; + push @warn, "item $itemcode: $@"; + return undef; + } $chr->{Description}= snarf('Description'); $chr->{Avail}= snarf('Stock Availability'); $chr->{MinOrder}= snarf('Minimum Order'); $chr->{Multiple}= snarf('Order Multiple'); + $price= snarf('Unit Price', "\n\