# HG changeset patch # User Matti Hamalainen # Date 1454108143 -7200 # Node ID bc7746ca622eddca9b92241dce33ab825b94fe3b # Parent 9dd4d2e3a4ac18ea3b29afb4da8306a312480690 fetch_weather: Implement purge_threshold setting. diff -r 9dd4d2e3a4ac -r bc7746ca622e config.fetch_weather.example --- a/config.fetch_weather.example Sat Jan 30 00:28:14 2016 +0200 +++ b/config.fetch_weather.example Sat Jan 30 00:55:43 2016 +0200 @@ -4,6 +4,17 @@ ### ## +## Purge time threshold for old/obsolete records. +## Fetch_weather stores data into a cache file, which +## also keeps older records as sometimes weather stations +## do not report reliably. However, too old records +## need to be purged. This setting sets the threshold +## time in MINUTES (default is 60 minutes) +## +purge_threshold = 60 + + +## ## Enable/disable data scraping from Tiehallinto's WWW-pages ## opt_tiehallinto = 1 diff -r 9dd4d2e3a4ac -r bc7746ca622e fetch_weather.pl --- a/fetch_weather.pl Sat Jan 30 00:28:14 2016 +0200 +++ b/fetch_weather.pl Sat Jan 30 00:55:43 2016 +0200 @@ -488,12 +488,15 @@ ### -### Purge very old entries +### Purge very old entries, default to 60 minutes ### my $wqtime = time(); +my $purge = opt_get_int("purge_threshold"); +$purge = 60 if ($purge <= 0); + foreach my $key (keys %$weatherdata) { - if ($wqtime - $weatherdata->{$key}[1] > (60*60*6)) + if ($wqtime - $weatherdata->{$key}[1] > (60 * $purge)) { delete $$weatherdata{$key}; }