ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/dinfo/dinfo-import1
Revision: 1.2
Committed: Mon Aug 25 15:58:13 2003 UTC (20 years, 8 months ago) by root
Branch: MAIN
Changes since 1.1: +14 -18 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/usr/bin/perl
2
3 use Carp;
4
5 use PApp::SQL;
6 use BerkeleyDB;
7
8 # 2031616: 0:435514 1:44163 2:107528 3:127671 4:8311 5:2028604 6:117468 7:8210 8:11754 9:24860 14:4344
9 # 4128768: 0:650846 1:92556 2:183027 3:170894 4:8605 5:4122242 6:147178 7:8238 8:11802 9:31453 14:6460
10
11 my @cvtid = (
12 [name => 0],
13 [vorname => 1],
14 [zusatz1 => 2],
15 [zusatz2 => 3],
16 [zusatz3 => 4],
17 [vorwahl => 5],
18 # nummer
19 [strasse => 7],
20 [haus => 8],
21 [plz => 9],
22 [ort => 10],
23 #[ort => 11], # Ortsteil
24 [branche => 12],
25 [typ => 13],
26 );
27
28 local $PApp::SQL::DBH = PApp::SQL::connect_cached "dinfo::", "DBI:mysql:dinfo";
29
30 sql_exec "truncate $_"
31 for qw(branche haus name ort plz row strasse typ vorname vorwahl zusatz1 zusatz2 zusatz3);
32
33 sql_exec "lock tables " . join ", ", map "$_ write",
34 qw(branche haus name ort plz strasse typ vorname vorwahl zusatz1 zusatz2 zusatz3);
35
36 # special treatment for name, due to it's size :(
37 unlink "/tmp/dinfo-import1-cache-$$";
38 tie %cache,
39 'BerkeleyDB::Btree',
40 -Filename => "/tmp/dinfo-import1-cache-$$",
41 -Flags => DB_CREATE,
42 -Cachesize => 380*1024*1024;
43
44 while (<STDIN>) {
45 chomp;
46 my @data = split /\t/;
47
48 $data[3] =~ s/^, //;
49 $data[7] =~ s/\.$// && $data[6] =~ s/ Geb$/Geb./;
50
51 $data[6] =~ /^((?:[a-zA-Z][-.\/a-zA-Z0-9]*)?) (?:\s*\+)? \s* ([0-9\ ]+)$/x or do {
52 warn "ERR: unparseable telnr. '$data[6]'";
53 next;
54 };
55
56 $data[6] = $2;
57 $data[13] = $1;
58
59 ($data[5] eq substr $data[6], 0, length $data[5])
60 and substr $data[6], 0, length $data[5], "";
61
62 if (length $data[6] > 12) {
63 warn "ERR: number too long '$data[6]'";
64 next;
65 }
66
67 for (@cvtid) {
68 my ($name, $idx) = @$_;
69 $data[$idx] = ($cache{"$idx,$data[$idx]"}
70 ||= sql_insertid sql_exec
71 "insert into $name (id, data) values (NULL, ?)", "$data[$idx]");
72 }
73
74 $data[13] < 16 or die "ERR: too many typ's";
75
76 $data[6] =~ s/ //g;
77 $data[6] = pack "H*", (substr "$data[6]000000000", 0, 12) . sprintf "%x%x", 12 - length $data[6], $data[13];
78 #warn unpack "H*", $data[6];
79 $data[6] =~ s/([\\\x0a\x09])/\\$1/g;
80 $data[6] =~ s/\x00/\\0/g;
81
82 #name vorname zusatz1 zusatz2 zusatz3 vorwahl nummer strasse haus plz ort branche
83
84 print +(join "\t",
85 $data[0], $data[1], $data[2], $data[3], $data[4],
86 $data[5], $data[6],
87 $data[7], $data[8], $data[9], $data[10], $data[12],
88 ), "\n";
89
90 $count++ & 4095 or warn time . " $count";
91 }
92