9 '/usr/share/mythtv/mythweather/scripts/us_nws',
10 '/usr/local/share/mythtv/mythweather/scripts/us_nws';
18 our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
23 my $email =
'gjhurlbu@gmail.com / ldunning@gmail.com';
26 my @
types = (
'18hrlocation',
'updatetime',
27 'temp-0',
'temp-1',
'temp-2',
'temp-3',
'temp-4',
'temp-5',
28 '18icon-0',
'18icon-1',
'18icon-2',
'18icon-3',
'18icon-4',
'18icon-5',
29 'pop-0',
'pop-1',
'pop-2',
'pop-3',
'pop-4',
'pop-5',
30 'time-0',
'time-1',
'time-2',
'time-3',
'time-4',
'time-5',
31 'copyright',
'copyrightlogo');
38 print "$name,$version,$author,$email\n";
43 print "$updateTimeout,$retrieveTimeout\n";
48 NWSLocation::AddLocSearch($search);
49 NWSLocation::AddStateSearch($search);
50 NWSLocation::AddStationIdSearch($search);
53 while($result = shift @$results) {
54 if ($result->{latitude} ne
"NA" && $result->{longitude} ne
"NA") {
55 print "$result->{latitude},$result->{longitude}::";
56 print "$result->{station_name}, $result->{state}\n";
73 my ($latitude, $longitude) = getLocation($locstr);
74 if (!(defined $opt_u && defined $latitude && defined $longitude
75 && $latitude ne
"" && $longitude ne
"")) {
102 if (
open (CACHE,
"$dir/ndfd18_cache_${latitude}_${longitude}")) {
104 # We don't have to check the start/end dates, since we get the same chunk
105 # every time, and we update the cache atleast every hour, which is how often the
106 # data is updated by the NWS.
107 if (Date_Cmp($nextupdate,
"now") > 0) { # use cache
108 no
strict "vars"; # because eval doesn
't scope var correctly
109 $result = eval <CACHE>;
113 print STDERR "Error parsing cache $@\n";
120 my $unit = ($units eq "SI" ? "m" : "e");
121 ($result, $creationdate) = NDFDParser::doParse($latitude, $longitude, $d1, $d2, $unit, $param);
123 open(CACHE, ">$dir/ndfd18_cache_${latitude}_${longitude}") or
124 die "cannot open cache ($dir/ndfd18_cache_${latitude}_${longitude}) for writing";
125 $Data::Dumper::Purity = 1;
126 $Data::Dumper::Sortkeys = 1;
127 $Data::Dumper::Indent = 0;
128 # NDFD is updated by 45 minutes after the hour, we'll give them until 50 to
135 $newmin = 60-($min-50);
137 $nextupdate = DateCalc(
"now",
"+ $newmin minutes");
139 print CACHE Dumper($result);
143 printf
"updatetime::Last Updated on %s\n",
144 UnixDate($creationdate,
"%b %d, %I:%M %p %Z");
145 print "copyright::National Digital Forecast Database\n";
146 print "copyrightlogo::none\n";
149 if (defined $result->{
$time}->{
'probability-of-precipitation_12 hour'}) {
150 $pop12 = $result->{
$time}->{
'probability-of-precipitation_12 hour'};
155 print "temp-${index}::$result->{$time}->{temperature_hourly}\n";
156 print "pop-${index}::$pop12 %\n";
157 $icon = $result->{
$time}->{
'conditions-icon_forecast-NWS'};
158 $icon =~ s/.*\/([a-z0-9
_]+[.][j][
p][
g])/$1/;
162 if (
$line =~ /${icon}::/) {
164 print "18icon-${index}::$line";
172 # This script will accept locations that are either station ids, or latitude
173 # longitude. This is because I haven't decided which to use yet :)
177 $str =~ tr/[a-
z]/[A-Z]/;
181 if ($str =~ m/[A-Z]{4,4}/) { # station
id form
182 NWSLocation::AddStationIdSearch($str);
184 }
else { # hopefully lat/lon
185 ($lat, $lon) = split /,/, $str;
186 $lat =~ s/(\d{1,3}([.]\d{1,3})?)([.]\d{1,3})?[N]/+$1/ or
187 $lat =~ s/(\
d{1,3}([.]\d{1,3})?)([.]\d{1,3})?[
S]/-$1/;
188 $lon =~ s/(\d{1,3}[.](\d{1,3})?)([.]\d{1,3})?[E]/+$1/ or
189 $lon =~ s/(\
d{1,3}([.]\d{1,3})?)([.]\d{1,3})?[W]/-$1/;
190 NWSLocation::AddLatLonSearch($lat, $lon);
194 if ($lat && $lon && !$results) {
195 # didn't find a matching station
196 print "18hrlocation::$lat,$lon\n";
200 # Should be one result in array
202 $lat = $location->{latitude};
204 if ($lat eq
'NA' || $lon eq
'NA') {
205 # maybe scrape them from website, since they are there, annoying that
206 # they aren't all in the XML file, gotta love the U.S. Gov :)
207 die "Latitude and Longitude do not exist for $str";
209 print "18hrlocation::$location->{station_name}, $location->{state}\n";