Mercurial > hg > lukkari
annotate parsedata.pl @ 51:0db0d485eb59
Rename some variables, remove "simple" mode.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Oct 2012 18:02:36 +0300 |
parents | bb00a40252e2 |
children | b2f45dd616bc |
rev | line source |
---|---|
1 | 1 #!/usr/bin/perl -w |
2 # | |
3 # Fetch and parse HTML format class timetable into more sane formats | |
32 | 4 # (C) Copyright 2010-2011 Matti Hämäläinen <ccr@tnsp.org> |
1 | 5 # |
6 use strict; | |
7 use Data::Dumper; | |
8 use HTML::Entities; | |
9 | |
10 | |
11 sub urlencode($) | |
12 { | |
13 my $value = $_[0]; | |
14 $value =~ s/([^a-zA-Z_0-9 ])/"%" . uc(sprintf "%lx" , unpack("C", $1))/eg; | |
15 $value =~ tr/ /+/; | |
16 return $value; | |
17 } | |
18 | |
19 | |
20 sub str_trim($) | |
21 { | |
22 my $str = $_[0]; | |
23 if (defined($str)) { | |
24 $str =~ s/^\s*//; | |
25 $str =~ s/\s*$//; | |
26 } | |
27 return $str; | |
28 } | |
29 | |
30 | |
31 sub pop_token_a($) | |
32 { | |
33 my $tokens = $_[0]; | |
34 return shift(@$tokens); | |
35 } | |
36 | |
37 | |
38 sub pop_token($) | |
39 { | |
40 return str_trim(pop_token_a($_[0])); | |
41 } | |
42 | |
43 | |
44 sub parse_html_str($) | |
45 { | |
46 my $tokens = $_[0]; | |
47 my $token = pop_token($tokens); | |
48 my $str = ""; | |
49 $token =~ s/^\s*//; | |
50 | |
51 return undef unless (substr($token, 0, 1) eq '"'); | |
52 $token = substr($token, 1); | |
53 | |
54 while (defined($token)) { | |
26 | 55 my $tmp = $token; |
25
a076d8d22422
Fix string parsing in the HTML parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
56 $tmp =~ s/\s*$//; |
a076d8d22422
Fix string parsing in the HTML parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
57 if (substr($tmp, -1) eq '"') { |
a076d8d22422
Fix string parsing in the HTML parser.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
58 $str .= substr($tmp, 0, -1); |
1 | 59 return $str; |
60 } else { | |
61 $str .= $token; | |
62 } | |
63 $token = shift(@$tokens); | |
64 } | |
65 return undef; | |
66 } | |
67 | |
68 | |
69 sub parse_html_tree($$); | |
70 | |
71 sub parse_html_tree($$) | |
72 { | |
73 my ($tokens, $tree) = @_; | |
74 | |
75 while (my $token = pop_token($tokens)) { | |
76 if ($token =~ /^<[!\/]?[a-zA-Z]+/) { | |
77 $token = lc($token); | |
78 if ($token =~ /^<\!.*>$/) { | |
79 # Ignore comments etc. | |
80 } elsif ($token =~ /^<([a-z]+)(.*)>$/) { | |
81 my ($name, $args) = ($1, $2); | |
82 if ($name eq "meta" || $name eq "img") { | |
83 my $tmp = {}; | |
84 parse_html_tree($tokens, $tree); | |
85 return $tree; | |
86 } else { | |
87 my $tmp = { "name" => $name, "args" => str_trim($args) }; | |
88 parse_html_tree($tokens, $tmp); | |
89 push(@{$$tree{"nodes"}}, $tmp); | |
90 } | |
91 } elsif ($token =~ /^<\/([a-z]+)>$/) { | |
92 return $tree; | |
93 } else { | |
94 die("HORROR TERROR ELITE: $token\n"); | |
95 } | |
96 } else { | |
97 $token = str_trim(decode_entities($token)); | |
98 push(@{$$tree{"nodes"}}, { "name" => "text", "args" => "", "text" => $token }) if length($token) > 0; | |
99 } | |
100 } | |
101 | |
102 return $tree; | |
103 } | |
104 | |
105 | |
106 sub parse_html($) | |
107 { | |
108 return undef unless defined($_[0]); | |
109 my $str = $_[0]; | |
110 my $res = { "name" => "", "args" => "" }; | |
111 $str =~ tr/\r/ /; | |
112 $str =~ tr/\n/ /; | |
113 my @tokens = grep { !($_ =~ /^\s*$/) } split(/(<\/?[a-zA-Z]+.*?>)/, $str); | |
114 parse_html_tree(\@tokens, $res); | |
115 return $res; | |
116 } | |
117 | |
118 sub html_find_node($$$); | |
119 | |
120 sub html_find_node($$$) | |
121 { | |
122 my ($node, $name, $args) = @_; | |
123 | |
124 if (defined($node)) { | |
125 if (ref($node) eq "ARRAY") { | |
126 foreach my $n (@$node) { | |
127 my $tmp = html_find_node($n, $name, $args); | |
128 # Must do it like this, in order not to break the loop | |
129 return $tmp if defined($tmp); | |
130 } | |
131 } elsif (ref($node) eq "HASH") { | |
132 if (defined($$node{"name"})) { | |
133 if ($$node{"name"} eq $name) { | |
134 if ($args ne "") { | |
135 if (defined($$node{"args"}) && $$node{"args"} =~ /$args/) { | |
136 } else { | |
33
ad96ed91de92
Fix recursive parsing with attributes.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
137 return html_find_node($$node{"nodes"}, $name, $args); |
1 | 138 } |
139 } | |
140 return $node; | |
141 } else { | |
142 return html_find_node($$node{"nodes"}, $name, $args); | |
143 } | |
144 } | |
145 } | |
146 } | |
147 return undef; | |
148 } | |
149 | |
150 | |
151 sub fnode($$) | |
152 { | |
153 return html_find_node($_[0], $_[1], ""); | |
154 } | |
155 | |
156 | |
157 sub fnodea($$$) | |
158 { | |
159 return html_find_node($_[0], $_[1], $_[2]); | |
160 } | |
161 | |
162 | |
163 sub escape($) | |
164 { | |
165 my $s = $_[0]; | |
166 $s =~ s/(['"])/\\$1/g; | |
167 return $s; | |
168 } | |
169 | |
170 | |
171 sub html_collapse($$); | |
172 | |
173 sub html_collapse($$) | |
174 { | |
175 my ($node, $strip) = @_; | |
176 my $str = ""; | |
177 | |
178 if ($$node{"name"} eq "text") { | |
179 $str .= $$node{"text"}; | |
180 } else { | |
181 $str .= "<".$$node{"name"}.">" unless ($strip); | |
182 foreach my $n (@{$$node{"nodes"}}) { | |
183 $str .= html_collapse($n, $strip); | |
184 } | |
185 $str .= "</".$$node{"name"}.">" unless ($strip); | |
186 } | |
187 | |
188 return $str; | |
189 } | |
190 | |
191 | |
192 ### | |
193 ### Main program | |
194 ### | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
195 my $modes = "php|xml"; |
1 | 196 my $opt_mode = "php"; |
197 my $opt_dump = 0; | |
198 my $opt_filename; | |
199 my $opt_outfile; | |
200 | |
201 while (defined(my $arg = shift)) { | |
202 if (substr($arg, 0, 1) eq "-") { | |
203 if ($arg =~ /^-($modes)$/o) { | |
204 $opt_mode = $1; | |
205 } | |
206 elsif ($arg eq "-dump") { | |
207 $opt_dump = 1; | |
208 } | |
209 elsif ($arg eq "-o") { | |
210 $opt_outfile = shift or die("Output filename option -o requires an argument.\n"); | |
211 } else { | |
212 die("Invalid option '$arg'.\n"); | |
213 } | |
214 } else { | |
215 $opt_filename = $arg; | |
216 } | |
217 } | |
218 | |
4
dd2bce7ec0c8
Removed http fetching feature, it's not really useful here.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
219 die("Usage: $0 [options] <filename> |
1 | 220 |
221 -php Output a PHP include file with data in arrays (default) | |
222 -xml Output XML. | |
223 | |
224 -o <filename> Set output filename. Default is to use stdout. | |
225 | |
226 -dump Dump HTML tree to stdout and quit. | |
227 | |
228 ") unless defined($opt_filename); | |
229 | |
230 | |
231 my $data; | |
36
bb00a40252e2
Input in ISO-8859-1 and output in UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
232 open(my $fh, '<:encoding(iso-8859-1)', $opt_filename) or die("Error opening '$opt_filename': $!\n"); |
4
dd2bce7ec0c8
Removed http fetching feature, it's not really useful here.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
233 $data = do { local $/; <$fh> }; |
dd2bce7ec0c8
Removed http fetching feature, it's not really useful here.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
234 close($fh); |
1 | 235 |
236 die("No data in input.\n") unless (defined($data) && $data ne ""); | |
237 | |
238 | |
239 # Filter out certain unneeded elements | |
240 $data =~ s/<font[^>]*>//ig; | |
241 $data =~ s/<\/font>//ig; | |
242 $data =~ s/<\/?center>//ig; | |
243 $data =~ s/<br>//ig; | |
244 $data =~ s/ / /ig; | |
245 | |
246 ### Get some general information | |
247 my $otree = parse_html($data); | |
248 if ($opt_dump) { | |
249 print Dumper(fnode($otree, "html")); | |
250 exit; | |
251 } | |
252 | |
253 my %class = (); | |
254 my $body = fnode($otree, "body"); | |
255 if (defined($body) && defined($$body{"nodes"})) { | |
256 foreach my $n (@{$$body{"nodes"}}) { | |
257 if ($$n{"name"} eq "text") { | |
258 push(@{$class{"info"}}, $$n{"text"}); | |
259 } | |
260 elsif ($$n{"name"} eq "b") { | |
261 push(@{$class{"data"}}, $n); | |
262 } | |
263 } | |
264 } | |
265 | |
266 # Filter out some more, for easier tree access during table parsing | |
267 $data =~ s/<\/?b>//ig; | |
268 my $tree = parse_html($data); | |
269 my $node = fnode(fnode($tree, "body"), "table"); | |
270 die("No table element found in document. Perhaps the format has changed? :(\n") unless defined($node); | |
271 | |
272 ### Parse through the HTML document node tree to find the data we need | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
273 my $cid = 0; |
1 | 274 my $q = $$node{"nodes"}; |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
275 my $hourDefs = {}; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
276 my $hourTable = {}; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
277 my $maxDays = 6; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
278 my $maxHours = 0; |
1 | 279 |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
280 # Skip zero position this way (can't use foreach here) |
1 | 281 for (my $i = 1; $i < scalar(@{$q}); $i++) { |
282 my $d = $$q[$i]{"nodes"}; | |
283 if (defined($d)) { | |
284 foreach my $n (@{$d}) { | |
285 my $l = $$n{"nodes"}[0]{"nodes"}; | |
286 if (defined($l) && $$n{"args"} =~ /colspan=6\s+rowspan=(\d+)/) { | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
287 my $chours = $1 / 2; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
288 my $cdata = []; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
289 my $cgrouped = 0; |
1 | 290 foreach my $h (@{$l}) { |
291 if (defined($$h{"nodes"})) { | |
292 foreach my $b (@{$$h{"nodes"}}) { | |
293 if (defined($$b{"nodes"})) { | |
294 my $text = $$b{"nodes"}[0]{"text"}; | |
295 $text =~ s/\.$//; | |
296 | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
297 $cgrouped = 1 if ($text =~ /vuorov/); |
1 | 298 |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
299 push(@$cdata, $text); |
1 | 300 } |
301 } | |
302 } | |
303 } | |
304 | |
305 my $tid; | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
306 if (scalar(@$cdata) > 0) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
307 $cid++; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
308 $tid = $cid; |
1 | 309 } else { |
310 $tid = 0; | |
311 } | |
312 | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
313 my $cday = 0; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
314 for (my $x = 0; $x < $maxDays; $x++) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
315 if (!defined($$hourTable{$maxHours}{$x})) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
316 $cday = $x; |
1 | 317 last; |
318 } | |
319 } | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
320 for (my $t = 0; $t < $chours; $t++) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
321 $$hourTable{$maxHours + $t}{$cday} = $tid; |
1 | 322 } |
323 | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
324 if (scalar(@$cdata) > 0) { |
1 | 325 # Grouped, if there is another class ID in second slot |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
326 $cgrouped = 1 if ($$cdata[1] =~ /^[A-Z]\d{6}$/); |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
327 $$hourDefs{$cid} = { "grouped" => $cgrouped, "day" => $cday, "start" => $maxHours, "hours" => $chours, "data" => $cdata }; |
1 | 328 } |
329 } | |
330 } | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
331 $maxHours++; |
1 | 332 } |
333 } | |
334 | |
335 | |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
336 ### Go through hour table, find last day and hour of the week, crop |
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
337 my $flag = 1; |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
338 for (my $y = $maxHours - 1; $y >= 0 && $flag; $y--) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
339 for (my $x = 0; $x < $maxDays && $flag; $x++) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
340 $flag = 0 if (defined($$hourTable{$y}{$x}) && $$hourTable{$y}{$x} != 0); |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
341 } |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
342 $maxHours-- if ($flag); |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
343 } |
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
344 |
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
345 $flag = 1; |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
346 for (my $x = $maxDays - 1; $x >= 0 && $flag; $x--) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
347 for (my $y = 0; $y < $maxHours && $flag; $y++) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
348 $flag = 0 if (defined($$hourTable{$y}{$x}) && $$hourTable{$y}{$x} != 0); |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
349 } |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
350 $maxDays-- if ($flag); |
8
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
351 } |
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
352 |
a52a0bdb5ea1
Crop off empty hours (time slots) and days.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
353 |
1 | 354 ### Open output file, if specified |
355 if (defined($opt_outfile)) { | |
356 open(STDOUT, '>', $opt_outfile) or die("Could not open output file '$opt_outfile'.\n"); | |
357 } | |
358 | |
36
bb00a40252e2
Input in ISO-8859-1 and output in UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
359 binmode STDOUT, ':encoding(utf-8)'; |
1 | 360 |
361 ### Output data in desired format | |
362 if ($opt_mode eq "php") { | |
363 print "<?\n". | |
364 "\$classInfo = array(\n". | |
365 " \"general\" => array(".join(", ", map { "\"".escape($_)."\""; } @{$class{"info"}})."),\n". | |
366 " \"info\" => array(".join(", ", map { "\"".escape(html_collapse($_, 1))."\""; } @{$class{"data"}})."),\n". | |
367 " \"info_tags\" => array(".join(", ", map { "\"".escape(html_collapse($_, 0))."\""; } @{$class{"data"}})."),\n". | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
368 " \"maxDays\" => $maxDays,\n". |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
369 " \"maxHours\" => $maxHours,\n". |
1 | 370 ");\n\n"; |
371 | |
372 print "\$classDefs = array(\n"; | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
373 foreach my $cid (sort { $a <=> $b } keys %{$hourDefs}) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
374 print " $cid => array("; |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
375 foreach my $key (keys %{$$hourDefs{$cid}}) { |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
376 my $a = $$hourDefs{$cid}{$key}; |
1 | 377 print "\"$key\" => "; |
378 if (ref($a) eq "ARRAY") { | |
379 print "array(".join(", ", map { "\"".escape($_)."\""; } @$a).")"; | |
380 } | |
381 elsif ($a =~ /^\d+$/) { | |
382 print $a; | |
383 } else { | |
384 print "\"".escape($a)."\""; | |
385 } | |
386 print ", "; | |
387 } | |
388 print "),\n"; | |
389 } | |
390 | |
391 print ");\n". | |
392 "\n". | |
393 "\$classHourTable = array(\n"; | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
394 for (my $y = 0; $y < $maxHours; $y++) { |
1 | 395 my $str = ""; |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
396 for (my $x = 0; $x < $maxDays; $x++) { |
1 | 397 $str .= ", " unless ($str eq ""); |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
398 $str .= sprintf "%3d", $$hourTable{$y}{$x}; |
1 | 399 } |
400 print " array(".$str."),\n"; | |
401 } | |
402 print ");\n?>\n"; | |
403 } | |
404 | |
405 elsif ($opt_mode eq "xml") { | |
406 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n". | |
407 "<timetable>\n". | |
408 " <class>\n". | |
409 " <general>".join("", map { "<node>".encode_entities($_)."</node>"; } @{$class{"info"}})."</general>\n". | |
410 " <info>".join("", map { "<node>".encode_entities(html_collapse($_, 1))."</node>"; } @{$class{"data"}})."</info>\n". | |
51
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
411 " <maxDays>$maxDays</maxDays>\n". |
0db0d485eb59
Rename some variables, remove "simple" mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
412 " <maxHours>$maxHours</maxHours>\n". |
1 | 413 " </class>\n"; |
414 | |
415 | |
416 print "</timetable>\n"; | |
417 } | |
418 | |
419 close (STDOUT); |