Skip to content

Commit b074b47

Browse files
author
Mark Kendall
committed
Merge branch 'master' of github.com:MythTV/mythtv
2 parents 2f93c0d + 85663d1 commit b074b47

File tree

3 files changed

+153
-16
lines changed

3 files changed

+153
-16
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DATA = ENVCAN-Stations.xml ENVCANParser.pm ENVCANLocation.pm ENVCAN_icons
22
DATA += ENVCANMapSearch.pm ENVCAN-Maps.xml
33

4-
SCRIPTS = envcan.pl envcan_animaps.pl
4+
SCRIPTS = envcan.pl envcan_animaps.pl envcan_maps.pl
55

66
include ../Makefile.inc
77

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";
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/perl
2+
# vim:ts=4:sw=4:ai:et:si:sts=4
3+
#
4+
# Static satellite map grabber for Environment Canada.
5+
#
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.
9+
#
10+
# The bulk of the code in this script was originally authored by
11+
# Lucien Dunning (ldunning@gmail.com).
12+
# Based on envcan_animaps.pl by Joe Ripley <vitaminjoe@gmail.com>
13+
14+
use strict;
15+
use warnings;
16+
17+
use English;
18+
use File::Path;
19+
use File::Basename;
20+
use Cwd 'abs_path';
21+
use lib dirname(abs_path($0 or $PROGRAM_NAME)),
22+
'/usr/share/mythtv/mythweather/scripts/ca_envcan',
23+
'/usr/local/share/mythtv/mythweather/scripts/ca_envcan';
24+
25+
use Getopt::Std;
26+
use LWP::Simple;
27+
use Date::Manip;
28+
use ENVCANMapSearch;
29+
use Image::Magick;
30+
31+
our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
32+
33+
my $name = 'ENVCAN-Static-Map';
34+
my $version = 0.1;
35+
my $author = 'Gavin Hurlbut';
36+
my $email = 'gjhurlbu@gmail.com';
37+
my $updateTimeout = 10*60;
38+
my $retrieveTimeout = 30;
39+
my @types = ('smdesc', 'updatetime', 'map', 'copyright');
40+
my $dir = "/tmp/envcan";
41+
42+
getopts('Tvtlu:d:');
43+
44+
if (defined $opt_v) {
45+
print "$name,$version,$author,$email\n";
46+
exit 0;
47+
}
48+
49+
if (defined $opt_T) {
50+
print "$updateTimeout,$retrieveTimeout\n";
51+
exit 0;
52+
}
53+
if (defined $opt_l) {
54+
my $search = shift;
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";
60+
}
61+
exit 0;
62+
}
63+
64+
if (defined $opt_t) {
65+
foreach (@types) {print; print "\n";}
66+
exit 0;
67+
}
68+
69+
if (defined $opt_d) {
70+
$dir = $opt_d;
71+
}
72+
73+
if (!-d $dir) {
74+
mkpath( $dir, {mode => 0755} );
75+
}
76+
77+
my $loc = shift;
78+
79+
if (!defined $loc || $loc eq "") {
80+
die "Invalid usage";
81+
}
82+
83+
# Get map info
84+
ENVCANMapSearch::AddAniSearch($loc);
85+
my $results = ENVCANMapSearch::doSearch();
86+
my $desc = $results->[0]->{satellite};
87+
88+
# Get HTML and find image list
89+
my $response = get $results->[0]->{animated_url};
90+
die unless defined $response;
91+
92+
my @image_list;
93+
my $size;
94+
my $base_url = "http://www.weatheroffice.gc.ca";
95+
my $file = $loc;
96+
my $path = "$dir/$file";
97+
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 >= 1) { shift @image_list; }
103+
}
104+
}
105+
106+
# Download map file, if necessary (maps are stale after 15 minutes)
107+
my $image = shift @image_list;
108+
my $ext = $image;
109+
$ext =~ s/.*\.(.*?)$/$1/;
110+
111+
my $cached = 0;
112+
if (-f "$path.$ext" ) {
113+
my @stats = stat(_);
114+
if ($stats[9] > (time - 900)) {
115+
$cached = 1;
116+
}
117+
}
118+
119+
if (!$cached) {
120+
getstore($base_url . $image, "$path.$ext");
121+
}
122+
123+
print "smdesc::$desc\n";
124+
print "map::$path.$ext\n";
125+
print "updatetime::Last Updated on " .
126+
UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";
127+
print "copyright::Environment Canada\n";

0 commit comments

Comments
 (0)