Skip to content

Commit 6574b9c

Browse files
committed
Fix Environment Canada animated maps.
As the support for the "pile of images" animation was removed to simplify the mythweather code, this script stopped working. Additionally, it was not returning any copyright data. As the requirement for Image::Magick has already been added for some of the mythnetvision scripts, there's little reason not to use it in mythweather. To fix this animation, we are now reading in each downloaded image in turn with Image::Magick, and making an animated GIF to pass to mythweather. Fixes #9467
1 parent 09800d6 commit 6574b9c

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

mythplugins/mythweather/mythweather/scripts/ca_envcan/envcan_animaps.pl

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/perl
2+
# vim:ts=4:sw=4:ai:et:si:sts=4
23
#
34
# Animated satellite map grabber for Environment Canada.
45
#
@@ -13,6 +14,7 @@
1314
use warnings;
1415

1516
use English;
17+
use File::Path;
1618
use File::Basename;
1719
use Cwd 'abs_path';
1820
use lib dirname(abs_path($0 or $PROGRAM_NAME)),
@@ -23,17 +25,18 @@
2325
use LWP::Simple;
2426
use Date::Manip;
2527
use ENVCANMapSearch;
28+
use Image::Magick;
2629

2730
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
2831

2932
my $name = 'ENVCAN-Animated-Map';
30-
my $version = 0.3;
33+
my $version = 0.4;
3134
my $author = 'Joe Ripley';
3235
my $email = 'vitaminjoe@gmail.com';
3336
my $updateTimeout = 10*60;
3437
my $retrieveTimeout = 30;
35-
my @types = ('amdesc', 'updatetime', 'animatedimage');
36-
my $dir = "./";
38+
my @types = ('amdesc', 'updatetime', 'animatedimage', 'copyright');
39+
my $dir = "/tmp/envcan";
3740

3841
getopts('Tvtlu:d:');
3942

@@ -66,6 +69,10 @@
6669
$dir = $opt_d;
6770
}
6871

72+
if (!-d $dir) {
73+
mkpath( $dir, {mode => 0755} );
74+
}
75+
6976
my $loc = shift;
7077

7178
if (!defined $loc || $loc eq "") {
@@ -97,24 +104,27 @@
97104

98105
# Download map files, if necessary (maps are stale after 15 minutes)
99106
my $i = 0;
107+
my $outimage = Image::Magick->new;
100108
foreach my $image (@image_list) {
101109
my $getImage = 1;
102-
if (-f $path . $i) {
110+
if (-f "$path$i" ) {
103111
my @stats = stat(_);
104-
if ($stats[9] > (time - 900)) { $i++; next; }
112+
if ($stats[9] > (time - 900)) {
113+
$outimage->Read( "$path$i" );
114+
$i++;
115+
next;
116+
}
105117
}
106118

107-
getstore($base_url . $image, $path . $i);
119+
getstore($base_url . $image, "$path$i");
120+
$outimage->Read( "$path$i" );
108121
$i++;
109122
}
110123

111-
# Determine image size
112-
if (!$size) {
113-
use Image::Size;
114-
my ($x, $y) = imgsize("${path}0");
115-
$size = "${x}x$y" if ($x && $y);
116-
}
124+
$outimage->Write( filename => "$dir/$file.gif", delay => 75 );
117125

118-
print "amdesc::$desc\n";
119-
printf "animatedimage::${path}%%1-$i%s\n", ($size && "-$size" || '');
120-
print "updatetime::Last Updated on " . UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";
126+
print "amdesc::$desc\n";
127+
print "animatedimage::$dir/$file.gif\n";
128+
print "updatetime::Last Updated on " .
129+
UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";
130+
print "copyright::Environment Canada\n";

0 commit comments

Comments
 (0)