/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 210 - (hide annotations)
Mon Dec 5 17:47:04 2005 UTC (18 years, 4 months ago) by dpavlin
File MIME type: text/plain
File size: 2713 byte(s)
 r11519@llin:  dpavlin | 2005-12-05 00:20:06 +0100
 partial changes to support multiple databases

1 dpavlin 74 #!/usr/bin/perl -w
2    
3     use strict;
4    
5     use Cwd qw/abs_path/;
6     use File::Temp qw/tempdir/;
7     use Data::Dumper;
8     use lib './lib';
9    
10     use WebPAC::Lookup;
11     use WebPAC::Input::ISIS;
12 dpavlin 209 use WebPAC::Store 0.03;
13 dpavlin 74 use WebPAC::Normalize::XML;
14     use WebPAC::Output::TT;
15 dpavlin 210 use WebPAC::Output::Estraier 0.02;
16 dpavlin 141 use YAML qw/LoadFile/;
17 dpavlin 210 use LWP::Simple;
18 dpavlin 74
19 dpavlin 76 my $limit = shift @ARGV;
20    
21 dpavlin 141 my $config = LoadFile('conf/config.yml');
22    
23     print "config = ",Dumper($config);
24    
25 dpavlin 210 die "no databases in config file!\n" unless ($config->{databases});
26 dpavlin 141
27 dpavlin 210 while (my ($database, $db_config) = each %{ $config->{databases} }) {
28 dpavlin 141
29 dpavlin 210 my $type = lc($db_config->{input}->{type});
30 dpavlin 74
31 dpavlin 210 die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis');
32 dpavlin 74
33 dpavlin 210 my $abs_path = abs_path($0);
34     $abs_path =~ s#/[^/]*$#/#;
35 dpavlin 141
36 dpavlin 210 my $lookup = new WebPAC::Lookup(
37     lookup_file => $db_config->{input}->{lookup},
38     );
39 dpavlin 141
40 dpavlin 210 my $db_path = $config->{webpac}->{db_path} . '/' . $database;
41 dpavlin 74
42    
43 dpavlin 210 my $log = $lookup->_get_logger;
44     $log->info("working on $database in $db_path");
45 dpavlin 74
46 dpavlin 210 my $isis = new WebPAC::Input::ISIS(
47     code_page => $config->{webpac}->{webpac_encoding},
48     limit_mfn => $db_config->{input}->{limit},
49     );
50 dpavlin 74
51 dpavlin 210 my $maxmfn = $isis->open(
52     filename => $db_config->{input}->{path},
53     code_page => $db_config->{input}->{encoding}, # database encoding
54     );
55 dpavlin 74
56 dpavlin 210 my $path = './db/';
57 dpavlin 74
58 dpavlin 210 my $db = new WebPAC::Store(
59     path => $db_path,
60     );
61 dpavlin 74
62 dpavlin 210 my $n = new WebPAC::Normalize::XML(
63     # filter => { 'foo' => sub { shift } },
64     db => $db,
65     lookup_regex => $lookup->regex,
66     lookup => $lookup,
67     );
68 dpavlin 74
69 dpavlin 210 $n->open(
70     tag => $db_config->{normalize}->{tag},
71     xml_file => $db_config->{normalize}->{path},
72     );
73 dpavlin 74
74 dpavlin 210 my $out = new WebPAC::Output::TT(
75     include_path => $config->{webpac}->{template_path},
76     filters => { foo => sub { shift } },
77     );
78 dpavlin 113
79 dpavlin 210 my $est_config = $config->{hyperestraier} || $log->logdie("can't find 'hyperestraier' part in confguration");
80     $est_config->{database} = $database;
81 dpavlin 113
82 dpavlin 210 $log->info("using HyperEstraier URL $est_config->{url}");
83 dpavlin 74
84 dpavlin 210 my $est = new WebPAC::Output::Estraier(
85     %{ $est_config },
86     );
87 dpavlin 74
88 dpavlin 210 my $total_rows = 0;
89 dpavlin 74
90 dpavlin 210 for ( 0 ... $isis->size ) {
91 dpavlin 74
92 dpavlin 210 my $row = $isis->fetch || next;
93 dpavlin 74
94 dpavlin 210 my $mfn = $row->{'000'}->[0] || die "can't find MFN";
95 dpavlin 113
96 dpavlin 210 my $ds = $n->data_structure($row);
97 dpavlin 113
98 dpavlin 210 # print STDERR Dumper($row, $ds);
99 dpavlin 113
100 dpavlin 210 # my $html = $out->apply(
101     # template => 'html_ffzg.tt',
102     # data => $ds,
103     # );
104     #
105     # # create test output
106     #
107     # my $file = sprintf('out/%02d.html', $mfn );
108     # open(my $fh, '>', $file) or die "can't open $file: $!";
109     # print $fh $html;
110     # close($fh);
111     #
112     # $html =~ s#\s*[\n\r]+\s*##gs;
113     #
114     # print STDERR $html;
115    
116     $est->add(
117     id => $mfn,
118     ds => $ds,
119     type => $config->{hyperestraier}->{type},
120     );
121    
122     $total_rows++;
123    
124     };
125    
126     $log->info("$total_rows records indexed");
127     }
128    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26