mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-02 23:28:28 +02:00
57fc0bd84e
generalizations. - boom/Makefile, dist/dk/Makefile: the "files with everything" are now called dist/db/all.* instead of dist/db/digi-key.* - boom/manu/panasonic/Makefile, boom/manu/stackpole/Makefile, boom/manu/yageo/Makefile: changed digi-key.equ to all.equ - boom/Makefile: there can now be a list of distributors - boom/Makefile (tar): new target to generate a snapshot of the database - boom/Makefile (PHONY): added "spotless" - boom/dist/dk/Makefile: do not merge catalog listings so that we don't have to search a huge cache with O(n^2) - boom/dist/dk/Makefile (clean, rebuild, update, spotless): targets for different degrees of rebuilding - boom/dist/dk/dk-db.pl: added progress report output
116 lines
2.1 KiB
Perl
Executable File
116 lines
2.1 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
sub rows
|
|
{
|
|
local $s = $_[0];
|
|
my @res = ();
|
|
|
|
while ($s =~ m#.*?<tr>(.*?)</tr>#) {
|
|
push(@res, $1);
|
|
$s = $';
|
|
}
|
|
return @res;
|
|
}
|
|
|
|
|
|
sub cols
|
|
{
|
|
local $s = $_[0];
|
|
my @res = ();
|
|
|
|
while ($s =~ m#.*?<td[^>]*>(.*?)</td>#) {
|
|
push(@res, $1);
|
|
$s = $';
|
|
}
|
|
return @res;
|
|
}
|
|
|
|
|
|
sub flush
|
|
{
|
|
$cmd = "wget -nv -O - ".join(" ",
|
|
map
|
|
"http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail\\&name=$_",
|
|
@pn);
|
|
$q .= `$cmd`;
|
|
@pn = ();
|
|
}
|
|
|
|
|
|
sub usage
|
|
{
|
|
print STDERR "usage: $0 (query [-i cache_file] | dsc | inv) [file ...]\n";
|
|
exit(1);
|
|
}
|
|
|
|
|
|
$mode = shift @ARGV;
|
|
&usage unless $mode eq "query" || $mode eq "dsc" || $mode eq "inv";
|
|
|
|
if ($mode eq "query") {
|
|
if ($ARGV[0] eq "-i") {
|
|
shift @ARGV;
|
|
$name = shift @ARGV;
|
|
open(OLD, $name) || die "$name: $!";
|
|
$q = join("", <OLD>);
|
|
($old = $q) =~ tr/\r\n//d;
|
|
close OLD;
|
|
}
|
|
|
|
while (<>) {
|
|
chop;
|
|
s/#.*//;
|
|
next if /^\s*$/;
|
|
next if /^\s/;
|
|
s/\s.*//;
|
|
|
|
$n++;
|
|
print STDERR "$n\r" unless $n % 100;
|
|
|
|
next if $old =~ m#align=right>Digi-Key Part Number</th><td>$_</td#;
|
|
push(@pn, $_);
|
|
&flush if @pn > 1000;
|
|
}
|
|
|
|
&flush if 0+@pn;;
|
|
|
|
print $q;
|
|
exit;
|
|
}
|
|
|
|
|
|
$q = join("", <>);
|
|
$q =~ tr/\r\n//d;
|
|
|
|
print "#DSC\n" if $mode eq "dsc";
|
|
print "#INV\n" if $mode eq "inv";
|
|
print "# MACHINE-GENERATED. DO NOT EDIT !\n";
|
|
print "# ", `date -u`;
|
|
|
|
for (split(/<!DOCTYPE HTML/, $q)) {
|
|
next unless m#align=right>Digi-Key Part Number</th><td>([^<]+)</td#;
|
|
$pn = $1;
|
|
$qty = 0;
|
|
if (m#align=right>Quantity Available</th><td[^>]*>([0-9,]+)<#) {
|
|
($qty = $1) =~ tr/,//d;
|
|
}
|
|
next unless m#align=right>Description</th><td>(.*?)</td#;
|
|
$dsc = $1;
|
|
next unless m#<table.*<th>Price Break<(.*?)</table>#;
|
|
if ($mode eq "dsc") {
|
|
print "DIGI-KEY $pn $dsc\n";
|
|
next;
|
|
}
|
|
print "DIGI-KEY $pn $qty USD";
|
|
for (&rows($1)) {
|
|
@c = &cols($_);
|
|
next unless $c[0] =~ /^[0-9,]+$/;
|
|
next unless $c[1] =~ /^[0-9.]+$/;
|
|
$c[0] =~ tr/,//d;
|
|
$c[1] =~ tr/,//d; # let's hope we don't need this one often :)
|
|
$c[1] =~ s/0+$// if $c[1] =~ /\./;
|
|
print " $c[0] $c[1]";
|
|
}
|
|
print "\n";
|
|
}
|