/[pgestraier]/trunk/data/convert.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

Contents of /trunk/data/convert.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations)
Thu May 26 13:57:32 2005 UTC (18 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1355 byte(s)
added year to index data

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 # score for words in title
6 my $title_rank = 3;
7
8 open(my $t, "gzip -cd trivia.list.gz |") || die "can't open trivia.list.gz: $!";
9
10
11 my $header = 1;
12 my ($title, $year) = ('',undef);
13 my $in = 0;
14 my $trivia = '';
15 my @qv;
16
17 sub qv {
18 my $t = shift || return;
19
20 sub qv_print {
21 my $v = shift || return '';
22 $v =~ s/(.*)\s*,\s*(.+)/$2 $1/g;
23 push @qv, $v;
24 return '';
25 }
26 $t =~ s#([_'])([^\1]+?)\1 \(qv\)#qv_print($2)#ge;
27 }
28
29 my $i = 0;
30
31 while(<$t>) {
32 if ($header && /^=====+/) {
33 $header = 0;
34 next;
35 }
36 next if $header;
37
38 if (/^#\s+(.*)\s*$/) {
39 $title = $1;
40 if ($title =~ m#\s*\((\d+)\)\s*$#) {
41 $year = $1;
42 } else {
43 $year = undef;
44 }
45
46 print "# $title ", ( $year ? "[$year]" : "" ), "\n";
47 next;
48
49 } elsif (/^-\s(.*)\s*$/) {
50 $in = 1;
51 $trivia = "$1\n";
52 qv($1);
53 } elsif (/^\s\s(.*)\s*$/) {
54 $trivia .= "$1\n";
55 qv($1);
56 } elsif (/^$/ && $in) {
57 $i++;
58 print "$i ";
59 my $out = '@title=' . $title . "\n" .
60 '@size=' . length($trivia) . "\n";
61 $out .= "year=$year\n" if ($year);
62 $out .= 'quote=' . join(",", @qv) . "\n" if (@qv);
63 $out .= "\n$trivia\n" .
64 ("\t$title\n" x $title_rank) .
65 "\t" . join("\n\t", @qv) . "\n";
66
67 open(my $t, "> trivia/$i.est") || die "can't open $i.est: $!";
68 print $t $out;
69 close($t);
70 $trivia = '';
71 @qv = ();
72 $in = 0;
73 } else {
74 print "#$_\n";
75 }
76
77 }
78

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26