Date:2010-09-11 22:12:05 (8 years 9 months ago)
Author:Werner Almesberger
Commit:6fc656fd7ff4ef6b447469c198f490f0728cd1c7
Message:Added Digi-Key catalog data for automated BOM processing.

- bom/dk/Makefile, bom/dk/dk-db.pl: Digi-Key catalog query environment from
gta02-core
- bom/dk/digi-key.equ: manufacturer-distributor equivalences for some parts
used in atusd and atusb
Files: bom/dk/Makefile (1 diff)
bom/dk/digi-key.equ (1 diff)
bom/dk/dk-db.pl (1 diff)

Change Details

bom/dk/Makefile
1CACHE=query.data
2
3.PHONY: update regen regenerate clean spotless
4
5all: digi-key.dsc digi-key.inv
6
7$(CACHE): digi-key.equ
8        awk '/^#END/ { exit } /^DIGI-KEY / { print $$2 }' \
9          digi-key.equ | \
10          perl ./dk-db.pl query \
11          `[ -r $(CACHE) ] && echo '' -i $(CACHE)` >_$@ || \
12          { rm -f $@ _$@; exit 1; }
13        mv _$@ $@
14
15digi-key.dsc: $(CACHE)
16        perl ./dk-db.pl dsc $(CACHE) >$@ || { rm -f $@; exit 1; }
17
18digi-key.inv: $(CACHE)
19        perl ./dk-db.pl inv $(CACHE) >$@ || { rm -f $@; exit 1; }
20
21update:
22        $(MAKE) clean all
23
24regen regenerate:
25        rm -f digi-key.dsc digi-key.inv
26        $(MAKE) all
27
28clean:
29        rm -f $(CACHE) _$(CACHE)
30
31#
32# we don't do a "make clean" on "make spotless", so that things like "make
33# optimist" don't erase the cache.
34#
35
36spotless:
37        rm -f digi-key.dsc digi-key.inv _$(CACHE)
bom/dk/digi-key.equ
1#EQU
2
3DIGI-KEY AT86RF230-ZU-ND ATMEL AT86RF230-ZU
4
5DIGI-KEY 336-1296-5-ND SILABS C8051F326-GM
6
7DIGI-KEY 732-2230-1-ND WURTH 748421245
8
9# resistors
10
11DIGI-KEY RMCF0402ZT0R00CT-ND STACKPOLE RMCF0402ZT0R00
12DIGI-KEY P0.0JCT-ND PANASONIC ERJ-2GE0R00X
13DIGI-KEY 311-0.0JRCT-ND YAGEO RC0402JR-070RL
14
15# caps
16
17DIGI-KEY 490-1320-1-ND MURATA GRM155R60J105KE19D
18DIGI-KEY 445-4998-1-ND TDK C1005X5R0J105K
19DIGI-KEY 478-2583-1-ND AVX 04026D105KAT2A
20
21DIGI-KEY 311-1018-1-ND YAGEO CC0402JRNP09BN220
22DIGI-KEY 490-1283-1-ND MURATA GRM1555C1H220JZ01D
23DIGI-KEY 445-1239-1-ND TDK C1005C0G1H220J
24
25DIGI-KEY 311-1020-1-ND YAGEO CC0402JRNP09BN330
26DIGI-KEY 490-3220-1-ND MURATA GRM1555C1H330JZ01D
27DIGI-KEY 445-1241-1-ND TDK C1005C0G1H330J
28
29DIGI-KEY 311-1035-1-ND YAGEO CC0402KRX7R9BB221
30DIGI-KEY 445-1254-1-ND TDK C1005X7R1H221K
31DIGI-KEY 490-1298-1-ND MURATA GRM155R71H221KA01D
bom/dk/dk-db.pl
1#!/usr/bin/perl
2
3sub rows
4{
5    local $s = $_[0];
6    my @res = ();
7
8    while ($s =~ m#.*?<tr>(.*?)</tr>#) {
9    push(@res, $1);
10    $s = $';
11    }
12    return @res;
13}
14
15
16sub cols
17{
18    local $s = $_[0];
19    my @res = ();
20
21    while ($s =~ m#.*?<td[^>]*>(.*?)</td>#) {
22    push(@res, $1);
23    $s = $';
24    }
25    return @res;
26}
27
28
29sub usage
30{
31    print STDERR "usage: $0 (query [-i cache_file] | dsc | inv) [file ...]\n";
32    exit(1);
33}
34
35
36$mode = shift @ARGV;
37&usage unless $mode eq "query" || $mode eq "dsc" || $mode eq "inv";
38
39if ($mode eq "query") {
40    if ($ARGV[0] eq "-i") {
41    shift @ARGV;
42    $name = shift @ARGV;
43    open(OLD, $name) || die "$name: $!";
44    $q = join("", <OLD>);
45    ($old = $q) =~ tr/\r\n//d;
46    close OLD;
47    }
48
49    while (<>) {
50    chop;
51    s/#.*//;
52    next if /^\s*$/;
53    next if /^\s/;
54    s/\s.*//;
55    next if $old =~ m#align=right>Digi-Key Part Number</th><td>$_</td#;
56    push(@pn, $_);
57    }
58
59    if (0+@pn) {
60    $cmd = "wget -nv -O - ".join(" ",
61      map
62      "http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail\\&name=$_",
63      @pn);
64    $q .= `$cmd`;
65    }
66
67    print $q;
68    exit;
69}
70
71
72$q = join("", <>);
73$q =~ tr/\r\n//d;
74
75print "#DSC\n" if $mode eq "dsc";
76print "#INV\n" if $mode eq "inv";
77print "# MACHINE-GENERATED. DO NOT EDIT !\n";
78print "# ", `date -u`;
79
80for (split(/<!DOCTYPE HTML/, $q)) {
81    next unless m#align=right>Digi-Key Part Number</th><td>([^<]+)</td#;
82    $pn = $1;
83    $qty = 0;
84    if (m#align=right>Quantity Available</th><td[^>]*>([0-9,]+)<#) {
85    ($qty = $1) =~ tr/,//d;
86    }
87    next unless m#align=right>Description</th><td>(.*?)</td#;
88    $dsc = $1;
89    next unless m#<table.*<th>Price Break<(.*?)</table>#;
90    if ($mode eq "dsc") {
91    print "DIGI-KEY $pn $dsc\n";
92    next;
93    }
94    print "DIGI-KEY $pn $qty USD";
95    for (&rows($1)) {
96    @c = &cols($_);
97    next unless $c[0] =~ /^[0-9,]+$/;
98    next unless $c[1] =~ /^[0-9.]+$/;
99    $c[0] =~ tr/,//d;
100    $c[1] =~ tr/,//d; # let's hope we don't need this one often :)
101    $c[1] =~ s/0+$// if $c[1] =~ /\./;
102    print " $c[0] $c[1]";
103    }
104    print "\n";
105}

Archive Download the corresponding diff file



interactive