1 |
adcroft |
1.1 |
#!/usr/local/bin/perl -w |
2 |
|
|
use strict; |
3 |
|
|
|
4 |
|
|
=pod |
5 |
|
|
|
6 |
|
|
This is an example program to index data stored in a MySQL database. |
7 |
|
|
|
8 |
|
|
In this example, a table is read that contains "minutes" from some |
9 |
|
|
organization's meetings. The text of the minutes was stored in a |
10 |
|
|
blob, compressed with zlib. |
11 |
|
|
|
12 |
|
|
This script reads the record from MySQL, uncompresses the text, and |
13 |
|
|
formats for swish-e. The example below uses HTML, but you could |
14 |
|
|
also format at XML, or even plain text. |
15 |
|
|
|
16 |
|
|
=cut |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
use DBI; |
20 |
|
|
use Compress::Zlib; |
21 |
|
|
use Time::Local; |
22 |
|
|
|
23 |
|
|
my %database = { |
24 |
|
|
dsn => 'dbi:mysql:test', |
25 |
|
|
user => 'user', |
26 |
|
|
password => 'pass', |
27 |
|
|
}; |
28 |
|
|
|
29 |
|
|
my $dbh = DBI->connect( @database{qw/ dsn user password /}, { RaiseError => 1 } ); |
30 |
|
|
|
31 |
|
|
my $sth = $dbh->prepare("select id, date, minutes from meetings"); |
32 |
|
|
|
33 |
|
|
$sth->execute(); |
34 |
|
|
|
35 |
|
|
while ( my( $id, $date, $minutes) = $sth->fetchrow_array ) { |
36 |
|
|
|
37 |
|
|
my $uncompressed = uncompress( $minutes ); |
38 |
|
|
|
39 |
|
|
my $unix_date = unixtime( $date ); |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
my $content = <<EOF; |
43 |
|
|
<html> |
44 |
|
|
<head> |
45 |
|
|
<title> |
46 |
|
|
Minutes for meeting on date $date |
47 |
|
|
</title> |
48 |
|
|
</head> |
49 |
|
|
<body> |
50 |
|
|
$uncompressed |
51 |
|
|
</body> |
52 |
|
|
</html> |
53 |
|
|
EOF |
54 |
|
|
|
55 |
|
|
my $length = length $content; |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
print <<EOF; |
60 |
|
|
Content-Length: $length |
61 |
|
|
Last-Mtime: $unix_date |
62 |
|
|
Path-Name: /minutes/index.cgi?id=$id |
63 |
|
|
Document-Type: HTML |
64 |
|
|
|
65 |
|
|
EOF |
66 |
|
|
print $content; |
67 |
|
|
|
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
sub unixtime { |
71 |
|
|
my ( $y, $m, $d ) = split /-/, shift; |
72 |
|
|
return timelocal(0,0,0,$d,$m-1,$y-1900); |
73 |
|
|
}; |
74 |
|
|
|