+aladin
[nethome.git] / public_html / cgi-bin / aladin
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 use LWP::Simple;
5 use HTML::Entities;
6 binmode STDOUT,":utf8";
7 $|=1;
8 my $args;
9 if (exists $ENV{"QUERY_STRING"}) {
10   0==@ARGV or die "ARGV count != 0";
11   $args=$ENV{"QUERY_STRING"};
12 } else {
13   1==@ARGV or die "ARGV count != 1";
14   $args=$ARGV[0];
15 }
16 my $URL="http://pr-asv.chmi.cz/aladin/index.php?$args";
17 my $URLhtml=encode_entities $URL;
18 if ($ENV{"GATEWAY_INTERFACE"}) {
19   print <<"EOH";
20 Content-type: text/html; charset=utf8
21 Pragma-directive: no-cache
22 Cache-directive: no-cache
23 Cache-control: no-cache
24 Pragma: no-cache
25 Expires: 0
26
27 EOH
28 }
29 print <<"EOH";
30 <html><head>
31 <title>aladin@{[ !$URLhtml?"":": $URLhtml" ]}</title>
32 <meta http-equiv="Content-Type" content="text/html; charset=utf8">
33 </head><body>
34 <form action="idnes-foto" method="get">
35         <input type="text" name="url" size="50" value="$URLhtml">
36         <input type="submit">
37 </form>
38 <hr>
39 EOH
40 my $content=get $URL;
41 print "<table><tr><th></th>",map(sprintf("<th>%02dh</th>",$_*6),0..3),"</tr>\n";
42 my $day="";
43 my $days=0;
44 my @day;
45 sub flushday() {
46   print "<tr><td>$day</td>\n";
47   if (!$days) {
48     unshift @day,"" while @day<4;
49   } else {
50     push @day,"" while @day<4;
51   }
52   print "<td>$_</td>\n" for @day;
53   print "</tr>\n";
54   @day=();
55   $days++;
56 }
57 while ($content=~m{\n<tr><td bgcolor=wheat align=center>([^<>]*)<br>.*?<td bgcolor=lightgrey align=center>\s*(?:<img src=(http://portal.chmi.cz/files/portal/docs/meteo/ov/aladin/results/public/mapy/data/\S+)|([^<>]+))}gs) {
58   if ($day ne $1) {
59     flushday() if @day;
60     $day=$1;
61   }
62   push @day,$3||"<img src=\"$2\">";
63 }
64 flushday();
65 print <<"EOH";
66 </table>
67 <hr>
68 <p>EOF</p>
69 </body></html>
70 EOH