summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2017-05-04 23:06:35 (GMT)
committerWerner Almesberger <werner@almesberger.net>2017-05-04 23:06:35 (GMT)
commit9d3d6533b1e54d783a8fb70bd201ffbe72ae601e (patch)
tree22a8853d9a592364e16eb6c9d71c8973ef38be24
parent1b4aa68cb17c01f38ae3c2ac462a3bfd425100c3 (diff)
downloadmisc-9d3d6533b1e54d783a8fb70bd201ffbe72ae601e.zip
misc-9d3d6533b1e54d783a8fb70bd201ffbe72ae601e.tar.gz
misc-9d3d6533b1e54d783a8fb70bd201ffbe72ae601e.tar.bz2
bom/dk2pricing.pl: update for latest page syntax
-rwxr-xr-xbom/dk2pricing.pl54
1 files changed, 24 insertions, 30 deletions
diff --git a/bom/dk2pricing.pl b/bom/dk2pricing.pl
index 868c7af..07e362d 100755
--- a/bom/dk2pricing.pl
+++ b/bom/dk2pricing.pl
@@ -2,8 +2,8 @@
#
# bom/dk2pricing.pl - Obtain stock and pricing for Digi-Key parts
#
-# Written 2014, 2016 by Werner Almesberger
-# Copyright 2014, 2016 by Werner Almesberger
+# Written 2014, 2016-2017 by Werner Almesberger
+# Copyright 2014, 2016-2017 by Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -82,51 +82,45 @@ sub lookup
{
local ($page) = @_;
- my $price = "Extended Price";
- my $qty = "Quantity Available";
- my $manu = "Manufacturer Part Number";
- my $dks = "Digi-Key Stock:";
- my $facs = "Factory Stock.*?:";
- my $q0 = 'quantity"? value="?0"?';
my $desc = 'itemprop="description">\s*([^<]*)\s*<';
- die unless $page =~ /$price(.*?)$qty(.*?)$manu/s;
+ # Price table
- my ($p, $q, $e) = ($1, $2, $');
my @p = undef;
- while ($p =~ /<tr>\s*<td.*?>((\d+,)*\d+)<.*?>((\d+,)*\d*\.\d*)</s) {
- local ($b, $u) = ($1, $3);
+ if ($page =~ /<table\s+id="product-dollars".*?>(.*?)<\/table>/s) {
+ $p = $1;
- $b =~ tr/,//d;
- $u =~ tr/,//d;
+ while ($p =~
+ /<tr>\s*<td.*?>((\d+,)*\d+)<.*?>((\d+,)*\d*\.\d*)</s) {
+ local ($b, $u) = ($1, $3);
- push(@p, $b, $u);
- $p = $';
+ $b =~ tr/,//d;
+ $u =~ tr/,//d;
+
+ push(@p, $b, $u);
+ $p = $';
+ }
+ } else {
+ die unless $page =~ /Obsolete item/;
}
+
local $t;
- # Digi-Key stock only
- if ($q =~ />\s*$dks\s+((\d+,)*\d+)\s*</) {
- $t = $1;
- # Digi-Key and factory stock (ignore the latter)
- } elsif ($q =~ />\s*$dks\s+((\d+,)*\d+)\s*<.*?>\s*$facs\\s+((\d+,)*\d+)\s*</) {
+ # Quantity Available
+
+ if ($page =~ /<span\s+id="dkQty">((\d+,)*\d+)<\/span>/s) {
$t = $1;
- # No stock
- } elsif ($q =~ /$q0/) {
- $t = 0;
- # Call
- } elsif ($q =~ /quantityavailable.*?>\s*0</) {
- $t = 0;
- # Can't figure it out
} else {
- die "can't figure out stock of $name";
+ $t = 0;
}
$t =~ tr/,//d;
unshift(@p, $t);
- $e =~ /$desc/s;
+ # Description
+
+ die unless $page =~ /$desc/s;
unshift(@p, $1);
return @p;