Browse files

Ignore time periods in the past for the Metoffice 18 hour grabber.

The feed doesn't always update on time so it's possible for one or
even two 'historical' time periods to precede the data we're
interested in. This just ignores any forecasts more than 3 hours in
the past, which is the duration of each forecast period.
  • Loading branch information...
1 parent 980be9f commit 52392963b380173f1e4343036f6814bd59a2f0af @stuartm stuartm committed Jul 29, 2012
View
7 mythplugins/mythweather/mythweather/scripts/uk_metoffice/metoffice_threehourapi.pl
@@ -22,6 +22,7 @@
use Date::Parse;
use Date::Calc qw(Day_of_Week);
+use DateTime;
use DateTime::Format::ISO8601;
use File::Basename;
use lib dirname($0);
@@ -142,6 +143,12 @@
my $datetime = DateTime::Format::ISO8601->parse_datetime(substr($item->{val}, 0, -1));
$datetime->add( minutes => $rep->{content} );
+
+ if ($datetime <= DateTime->now()->subtract( hours => 3 )) # Ignore periods in past
+ {
+ next;
+ }
+
printf "time-" . $i . "::" . MetOffCommon::format_date($datetime->epoch) . "\n";
my $iconname = "unknown";
switch ($rep->{W}) { # Weather Type

0 comments on commit 5239296

Please sign in to comment.