chiark / gitweb /
resistor converter mk 1
authorian <ian>
Wed, 14 Apr 2004 16:19:38 +0000 (16:19 +0000)
committerian <ian>
Wed, 14 Apr 2004 16:19:38 +0000 (16:19 +0000)
farnell/farnell-resistor-convert.pl [new file with mode: 0755]

diff --git a/farnell/farnell-resistor-convert.pl b/farnell/farnell-resistor-convert.pl
new file mode 100755 (executable)
index 0000000..d8ed939
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+# ways to invoke:
+#  1. Get a search list from farnell and feed HTML source to
+#     this script with no args.  Will produce part number list.
+#  2. Feed one or more outputs from farnell-find <item> to
+#     this script with args  <mfprefix> <valueprefix>...
+#     where <mfprefix> is the re for the first part of the mfr
+#     code and <valueprefix> is the words of the part name prefix.
+if (@ARGV>=2) {
+    ($kind,@prefix)= @ARGV;
+    while (<STDIN>) {
+       if (m/^Avail\s/) {
+           undef $value;
+       } elsif (m/^Description\s+\[$kind (\d[0-9MKR]+)\]\s+RESISTOR/) {
+           $value= lc $1;
+       } elsif (m/^Description\s+(\S.*)/) {
+           print "#  $1\n";
+           $value= '';
+       } elsif (m/^Item\s+([-0-9]+)$/) {
+           die unless defined $value;
+           next unless length $value;
+           printf "%s\t%s\n", join(' ',@prefix,$value), $1;
+           undef $value;
+       }
+    }
+} elsif (!@ARGV) {
+    while (<STDIN>) {
+       if (m/viewproductdetails.*\?prodId\=(\d{3})(\d{3,7})\"/) {
+           print "$1-$2\n" or die $!;
+       }
+    }
+} else {
+    die;
+}