-
Notifications
You must be signed in to change notification settings - Fork 0
/
gva_trafic_cameras.cgi
executable file
·58 lines (53 loc) · 1.85 KB
/
gva_trafic_cameras.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl --
use strict ;
use warnings ;
use CGI ;
use CGI::Carp qw(fatalsToBrowser);
use LWP ;
use Data::Dumper ;
use JSON ;
$|++;
my $q = new CGI ;
# for help, point your browser to
#
my $url = "http://ge.ch/ags1/rest/services/SITG/INFOMOBILITE_DATA/MapServer/3/query?outFields=*&where=1%3D1&f=json&returnGeometry=true" ;
my $filename = 'jsonCached.txt' ; # copy this file in the same directory as this script
print "Content-Type: text/html; charset=ISO-8859-1\n\n";
print "<head>" ;
print "<meta http-equiv=\"refresh\" content=\"60\">\n";
print "<title>Traffic Cameras Geneva</title></head>\n";
print "<body>\n";
&printList ;
print "</body>\n";
exit(0);
###############################################################################
sub printList {
my $ua = LWP::UserAgent->new( );
$ua->timeout( 2 ) ;
my $content ;
open(FILE, $filename) or die "Can't read file '$filename' [$!]\n";
$content = <FILE>;
close (FILE);
my $json = JSON->new->utf8;
my $perl_scalar = $json->decode( $content );
#print "<pre>", Dumper $perl_scalar, "</pre>" ; exit ;
my $camPerLine = 3 ;
my $camCount = 0 ;
print qq{<table border='0'>};
foreach my $location ( @{$perl_scalar->{ features }} ) {
$camCount++ ;
$camCount = 1 if ( $camCount > $camPerLine ) ;
print "<tr>" if ( $camCount == 1 ) ;
print "<td align='center'><b>" ;
foreach my $dir ( qw(ALLER RETOUR) ) {
my $caption = $location->{ attributes }->{ NOM } . " - " . $location->{ attributes }->{ "DIRECTION_$dir" } ;
print "<a href='" . $location->{ attributes }->{ "IMAGE_$dir" } . "'>" ;
print "<img src='" . $location->{ attributes }->{ "IMAGE_$dir" } . "' alt='$caption'/></a><br>" ;
print "$caption<br>" ;
}
print "</td>" ;
print "</tr>\n" if ( $camCount == $camPerLine ) ;
}
print qq{</table>};
}
###############################################################################