0: # Takes raw cuecat output and looks up the barcode scanned
1: # through upcdatabase.com
2: # I DID NOT WRITE THE SECTION THAT DOES THE DECODING
3: # and at the moment the name of the person who did escapes
4: # me
5: use LWP::Simple;
6: $seq = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-';
7:
8: sub decode
9: {
10: ($encoded) = @_;
11: @s = map { index($seq,$_); } split(//,$encoded);
12: $l = ($#s+1) % 4;
13: if ($l)
14: {
15: if ($l == 1)
16: {
17: print "Error!";
18: return;
19: }
20: $l = 4-$l;
21: $#s += $l;
22: }
23: $r = '';
24: while ($#s >= 0)
25: {
26: $n = (($s[0] << 6 | $s[1]) << 6 | $s[2]) << 6 | $s[3];
27: $r .=chr(($n >> 16) ^ 67) .
28: chr(($n >> 8 & 255) ^ 67) .
29: chr(($n & 255) ^ 67);
30: @s = @s[4..$#s];
31: }
32: $r = substr($r,0,length($r)-$l);
33: return $r;
34: }
35: chomp($s = <STDIN>);
36: @fields = split(/\./,$s);
37: @results = map(decode($_), @fields[1..$#fields]);
38:
39: $code = $results[2];
40:
41: $upcdata = get("http://www.upcdatabase.com/item.pl?upc=$code");
42:
43: $upcdata =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
44:
45: $upcdata =~ /Description(.*)\n/;
46:
47: print "\n\n$1\n";
48:
49: $upcdata =~ /Manufacturer(.*)\n/;
50:
51: print "Made by: $1\n";
52:
53: $upcdata =~ /Size\/Weight(.*)\n/;
54:
55: print "Size: $1"; In reply to UPCdatabase lookup in perl by beretboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |