2 # vim:ts=4:sw=4:ai:et:si:sts=4
4 # Animated satellite map grabber for Environment Canada.
6 # This script downloads satellite map data from the Environment Canada
7 # website. It uses the lists of JPEG images supplied by the page at
8 # http://www.weatheroffice.gc.ca/satellite/index_e.html.
10 # The bulk of the code in this script was originally authored by
11 # Lucien Dunning (ldunning@gmail.com).
20 use lib dirname(abs_path($0 or $PROGRAM_NAME)),
21 '/usr/share/mythtv/mythweather/scripts/ca_envcan',
22 '/usr/local/share/mythtv/mythweather/scripts/ca_envcan';
30 our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
32 my $name = 'ENVCAN-Animated-Map';
34 my $author = 'Joe Ripley / Gavin Hurlbut';
35 my $email = 'vitaminjoe@gmail.com / gjhurlbu@gmail.com';
36 my $updateTimeout = 10*60;
37 my $retrieveTimeout = 30;
38 my @types = ('amdesc', 'updatetime', 'animatedimage', 'copyright',
40 my $dir = "/tmp/envcan";
45 print "$name,$version,$author,$email\n";
50 print "$updateTimeout,$retrieveTimeout\n";
55 ENVCANMapSearch::AddSatSearch($search);
56 ENVCANMapSearch::AddSatClassSearch($search);
57 ENVCANMapSearch::AddImageTypeSearch($search);
58 foreach my $result (@{ENVCANMapSearch::doSearch()}) {
59 print "$result->{entry_id}::($result->{satellite_class}) $result->{satellite} $result->{image_type}\n";
65 foreach (@types) {print; print "\n";}
74 mkpath( $dir, {mode => 0755} );
79 if (!defined $loc || $loc eq "") {
84 ENVCANMapSearch::AddAniSearch($loc);
85 my $results = ENVCANMapSearch::doSearch();
86 my $desc = $results->[0]->{satellite};
88 # Get HTML and find image list
89 my $response = get $results->[0]->{animated_url};
90 die unless defined $response;
94 my $base_url = "http://www.weatheroffice.gc.ca";
96 my $path = "$dir/$file-";
98 # Get list of images (at most 10)
99 foreach my $line (split(/\n/, $response)) {
100 if ($line =~ /theImagesComplete\[\d*\] \= \"(.*)\"\;/) {
101 push (@image_list, $1);
102 if ($#image_list >= 10) { shift @image_list; }
106 # Download map files, if necessary (maps are stale after 15 minutes)
108 my $outimage = Image::Magick->new;
109 foreach my $image (@image_list) {
113 if ($stats[9] > (time - 900)) {
114 $outimage->Read( "$path$i" );
120 getstore($base_url . $image, "$path$i");
121 $outimage->Read( "$path$i" );
125 $outimage->Write( filename => "$dir/$file.gif", delay => 75 );
127 print "amdesc::$desc\n";
128 print "animatedimage::$dir/$file.gif\n";
129 print "updatetime::Last Updated on " .
130 UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";
131 print "copyright::Environment Canada\n";
132 print "copyrightlogo::none\n";