diff --git a/bin/user/forecast.py b/bin/user/forecast.py index 443fb45..ec7aa24 100644 --- a/bin/user/forecast.py +++ b/bin/user/forecast.py @@ -113,7 +113,11 @@ # to your location. # National Weather Service location identifier - lid = MAZ014 + lid = MAZ005 + + # lid_desc disambiguates when a lid is listed more than once in the document. + # If lid_desc is not specified, the first entry for the specified lid is used. + lid_desc = Lowell-Middlesex MA # National Weather Service forecast office identifier foid = BOX @@ -555,7 +559,7 @@ from weewx.engine import StdService from weewx.cheetahgenerator import SearchList -VERSION = "3.4.0b11" +VERSION = "3.4.0b12" if weewx.__version__ < "4": raise weewx.UnsupportedFeature( @@ -1663,6 +1667,7 @@ def __init__(self, engine, config_dict): self.url = d.get('url', NWS_DEFAULT_PFM_URL) self.max_tries = int(d.get('max_tries', 3)) self.lid = d.get('lid', None) + self.lid_desc = d.get('lid_desc', None) self.foid = d.get('foid', None) errmsg = [] @@ -1676,8 +1681,8 @@ def __init__(self, engine, config_dict): logerr('%s: forecast will not be run' % NWS_KEY) return - loginf('%s: interval=%s max_age=%s lid=%s foid=%s' % - (NWS_KEY, self.interval, self.max_age, self.lid, self.foid)) + loginf('%s: interval=%s max_age=%s lid=%s lid_desc=%s foid=%s' % + (NWS_KEY, self.interval, self.max_age, self.lid, self.lid_desc, self.foid)) self._bind() def get_forecast(self, dummy_event): @@ -1689,10 +1694,14 @@ def get_forecast(self, dummy_event): return None if self.save_raw: self.save_raw_forecast(text, basename='nws-raw') - matrix = NWSParseForecast(text, self.lid) + matrix = NWSParseForecast(text, self.lid, self.lid_desc) if matrix is None: - logerr('%s: no PFM found for %s in forecast from %s' % - (NWS_KEY, self.lid, self.foid)) + if self.lid_desc is None: + logerr('%s: no PFM found for %s in forecast from %s' % + (NWS_KEY, self.lid, self.foid)) + else: + logerr('%s: no PFM found for %s/%s in forecast from %s' % + (NWS_KEY, self.lid, self.lid_desc, self.foid)) return None logdbg('%s: forecast matrix: %s' % (NWS_KEY, matrix)) records = NWSProcessForecast(self.foid, self.lid, matrix) @@ -1762,7 +1771,7 @@ def NWSDownloadForecast(foid, url=NWS_DEFAULT_PFM_URL, max_tries=3): logerr('%s: failed to download forecast' % NWS_KEY) return None -def NWSExtractLocation(text, lid): +def NWSExtractLocation(text, lid, lid_desc=None): """Extract a single location from a US National Weather Service PFM.""" alllines = text.splitlines() @@ -1774,17 +1783,20 @@ def NWSExtractLocation(text, lid): elif lines is not None: if line.startswith('$$'): break + elif lines is not None and len(lines) == 1 and lid_desc is not None and line != lid_desc: + # It's not the reight lid_desc. Keep looking. + lines = None else: lines.append(line) return lines -def NWSParseForecast(text, lid): +def NWSParseForecast(text, lid, lid_desc=None): """Parse a United States National Weather Service point forcast matrix. Save it into a dictionary with per-hour elements for wind, temperature, etc. extracted from the point forecast. """ - lines = NWSExtractLocation(text, lid) + lines = NWSExtractLocation(text, lid, lid_desc) if lines is None: return None diff --git a/changelog b/changelog index e1bce87..df6289a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,16 @@ +3.4.0b12 +* NWS foid: BOX, lid: MAZ005 has multiple entries (actually, this is common) + the forecast plugin picks the first one found. To pick a different one, + specify the location text as the lid_desc parameter. + [Forecast] + [[NWS]] + lid = MAZ005 + lid_desc = Lowell-Middlesex MA + foid = BOX + Note: This is not required and, to speicify it, you need to examine + the report returened from NWS. Most users should ignore this + change. + 3.4.0b11 * Add missing freezing rain icon. * Fix for WU tempMin/tempMax. diff --git a/install.py b/install.py index c097d9c..d1fab05 100644 --- a/install.py +++ b/install.py @@ -10,7 +10,7 @@ def loader(): class ForecastInstaller(ExtensionInstaller): def __init__(self): super(ForecastInstaller, self).__init__( - version="3.4.0b11", + version="3.4.0b12", name='forecast', description='Generate and display weather and tide forecasts.', author="Matthew Wall", diff --git a/readme.txt b/readme.txt index fe5bd41..7b9b049 100644 --- a/readme.txt +++ b/readme.txt @@ -84,8 +84,14 @@ wee_extension --install weewx-forecast-3.4.0b11.zip [Forecast] [[NWS]] - lid = MAZ014 # specify a location identifier - foid = BOX # specify a forecast office identifier + lid = MAZ005 # specify a location identifier + foid = BOX # specify a forecast office identifier + lid_desc = Framingham-Middlesex MA # (optional) specify a lid description for cases + # where the lid is repeated in the forecast file + # and the user does not want the first entry for that lid. + # Just omit this entry entirely unless you have examined + # the forecast file and know the description of the repeated + # lid entry that you want to use. [[WU]] api_key = XXXXXXXXXXXXXXXX # specify a weather underground api_key # A location may be specified. If it isn't, your stations lat/long