Since the next version will require Python 3.9 or later due to
relying on the zoneinfo module, go ahead and clean up code that
supported earlier versions of the interpreter as well as updating
documentation accordingly.
Instead of using a naive time comparison, check times relative to
the user's time zone (shifted to UTC) and the expiration times
embedded in NWS documents (implicitly UTC).
Drop the ugly hack of the 24-hour expiry delay, but keep it at 1
hour to still provide some protection against premature filtering in
case someone switches into or out of DST on a different date than
NWS expects it to happen.
At some point, the NWS stopped printing its name in all capitals in
alerts and forecasts, which had the effect of turning off the
"smart" header/footer trimming in the script. Switch to match the
current string they've been using lately.
Some NWS products, such as forecasts and other alerts, have
expiration times marked relative to the issuing authority's local
time zone. In preparation for being able to calculate expirations
accurately relative to the user's local time, embed IANA TZDB
compliant identifiers in all WX weather zone definitions, translated
from their NWS time zone codes.
Correlation files are all updated because of amending overrides
accordingly.
NWS switched to using FIPS based county designations for flood
warnings around 2016, so fix the URLs for them. Also flash flood
statements and warnings (but nor watches which, for some reason,
still use WX weather zones). Severe weather statements too (but not
special weather statements nor urgent weather messages). Oh, and
thunderstorms.
Add a new tornado alert type with relevant URLs, and fix
configuration examples which reference the older tornado_warning
field which hasn't been available for years.
While at it, remove the separate flood statement alert which seems
to be entirely unused by NWS.
Since NWS alerts and forecasts list their expiration times relative
to the issuing office's local timezone, filtering for expired
documents relative to the users timezone can lead to them being
filtered early when they're not both coincidentally the same.
Introduce a one day (86400 second) offset buffer as a simple
workaround for now, since the user's and issuing authority's
timezones shouldn't ever differ by more than that. This has a
downside of showing forecasts or alerts which have expired and not
been replaced, but that was possible already if timezones differed
in the other direction, and is preferable to the alternative.
The NWS DBX schema for WX weather zones does include a field for a
timezone code, so a future change may introduce more accurate
calculations in order to identify the relative offset between the
user and issuer, but this will require extending our own zones
format to add a new value for it.
Switch to the 2022 US Census Bureau data, March 2023 NWS WX zones,
latest OurAirports open data set, and refreshed active forecast and
station lists. Regenerate all correlation sets based on these
updated sources.
This patch was helpfully submitted by Bas Couwenberg to drop use of
the universal newline flag, since Python 3.11 no longer supports it.
It probably breaks the ability to build new correlation files under
Python 2.7 and earlier, but since it shouldn't affect operation of
the utility with prebuilt correlations (the way it's typically
used), this isn't yet considered to drop Python 2.7 support
altogether.
The correlate() function stopped needing tarfile a couple of years
ago (version 2.4), but it was overlooked that the script continued
to unnecessarily import it. Clean this up.
Apparently, Python on Windows defaults to assuming CP1252 encoding
unless otherwise specified, as opposed to the UTF-8 assumption made
on POSIX platforms. Since our configuration and data files are
expected to always use UTF-8 encoding, be clear in the
ConfigParser.read() calls about that. We only do this under Python
3.x, as that method doesn't have an encoding parameter in 2.7.
Thanks to Lance Bermudez for reporting this.
Just a basic correlation update based on more recent active METAR
station and WX zone lists. Also update the copyright year for files
which have been edited so far in 2021 as well as in the LICENSE
file.
The selections proxy class, which mashes together command-line
arguments and configuration options, contained a longstanding and
fatal flaw with its handling of boolean values. In particular,
falsey values were consistently treated as truthy due to naively
recasting str to bool (which will always yield True unless empty).
This went unnoticed for so long because the majority of these
settings default to False, meaning the only reason most users had to
set them was to override them to True.
Many thanks to Jordan Russell for bringing this bug to my attention,
and for supplying an initial patch on which this fix is heavily
based.
Co-Authored-By: Jordan Russell
Julien Palard pointed out that the way URLError exceptions were
being manually cobbled into the stderr stream wasn't quite working
(thanks!), but it was also unnecessarily complicated for reasons I
don't recall now. Rip most of it out and just go with a basic
catch/error/re-raise there instead.
As a more complete fix and future-proofing for the earlier mismatch
between default_atypes and the alert URLs generated for WX zones
during correlation, stop aborting and simply add a warning if a
requested alert type has no corresponding URL.
Kevin Monceaux reported a regression with the 2.4 release. Running
with the -a/--alert option and no limited --atypes or atypes
override in weatherrc resulted in a message about undefined URLs
and no normal output. This problem crept in when hard-coding alert
types in the correlator after ditching the woefully unmaintained
zonecatalog.curr.tar data source (commit 8a37edd).
Update default_atypes so that it covers all relevant non-forecast
URLs the correlate routine embeds.
While auditing Debian's packages, Chris Lamb reported[*] that
weather-util's correlation set generation is not reproducible
because it embeds timestamps without a means to override them and
also varies by system timezone. Allow SOURCE_DATE_EPOCH from the
calling environment and assume UTC rather than relying on locale
settings when no timezones are specified.
[*] https://bugs.debian.org/964721
Update a bunch of the parsing for various correlation source files
to work in both Python 2.7 and 3.5+, mostly where str vs bytes and
UTF-8 encoding/decoding are concerned. This can be cleaned up
significantly once support for 2.7 is finally dropped.
Add a copyright header to the .gitignore file with start and end
years determined from its commit history. Add copyright headers for
the current year to overrides.log and qa.log, and also add
functionality to correlate() which adds these headers from now on.
Update the copyright year on overrides.conf, which was missed in
8a37edd and later commits. All files tracked in this repository now
declare a copyright and refer to the main LICENSE file for licensing
terms.
Solve a SyntaxWarning under Python 3.8 and later for use of the "is"
identity operator when comparing literals, by replacing with the
"==" equality operator.
When mangling URLs of fetched data to store in the local cache, only
split on the first colon so that URLs with port numbers in them are
properly differentiated. Previously, all URLs for the same domain
name landed in a single file if a port number was included, causing
incorrect results to be returned from the cache.
Fix a cache corruption issue by using a new "cached" field to hold
the timestamp for cached correlation search results. Previously the
"description" field was being overloaded, but this could cause the
cache to no longer load because of duplicate fields.
Python 2.7 is likely the only Python 2 anyone is using any longer
(even that's well past EOL upstream now), and reasonably recent
versions of 2.7 it need the same decode hack as Python 3 anyway when
dealing with some retrieved content. Just get rid of the version
detection and do it under any version.
Thanks to Bill Agee for suggesting the Hong Kong Observatory's
weather forecast page. A custom filter is implemented to strip the
forecast text from the HTML page in which it is embedded (if anyone
finds a plaintext version published at an alternate URL, let me know
and I'll rip out the extra routine).
Remove the stale metar.tbl and zonecatalog.curr.tar, which the USA
NWS hasn't been updating for many years, and add the public domain
airports.csv file from the amazing ourairports.com community. Also
update to latest (2019) USA Census Bureau location data, March 2020
WX zone information, cooperative sites list from 2018 (latest), and
regenerated active station and zone lists. Loss of the zonecatalog
necessitates directly applying various forecast and alert URL
patterns, though some which appeared unused by NWS for many years
were not included.
Clear out all old overrides, since the vast majority are obsoleted
by refreshed data, and build fresh correlation sets from the above
sources. Basically all sites have switched from HTTP to HTTPS, so
update URLs for this too.
One piecemeal use of the retired weather.noaa.gov/pub URL was missed
in the correlate() function, causing it to be reintroduced for
zone-based reports (such as forecasts) in a subsequent correlation
dataset update. Correct the invalid URLs in the zones file, and
update the correlation routine to embed the correct and working
tgftp.nws.noaa.gov hostname instead.
* weather.py(correlate): Note the updated URL to Census Bureau data
in file comments, and make the County-Public Forecast Zones
Correlation File parsing more robust against errors in the file
formatting.
* weather.py(correlate): The radian values in data files have a tendency
to vary by the tiniest rounding errors from one Python release to
another. By truncating them to the 7th decimal place, which is still
sub-meter resolution, this problem is minimized and the resulting data
diffs become far less noisy.
* weather.py(correlate): Previously the airports, places, stations,
zctas and zones files lacked trailing newlines, so this trivial patch
adds them before each is closed for writing.
* weather.py(correlate): The United States Census Bureau altered the
format of their 2010 Gazetteer on August 22, 2012, adding and reordering
a few fields. The previous version of the parser assumed a fixed field
order and ceased to work with the updated data files, so now the order
is inferred from the column headings in the first line of each file
instead.
* weather.1(INPUT FILES): Updated the list of potential weatherrc
locations to reflect those mentioned in the INSTALL file, particularly
the addition of /etc/weather/weatherrc in the 2.0 release.
* weather.py(get_config): Adjusted the configuration search locations to
include /etc/weather/weatherrc, since the INSTALL file started
mentioning it in the 2.0 release even though it wasn't actually
implemented as pointed out by Ben Kohler.
* Release 2.0: Heavy rewrite with too many new features to enumerate
here in the ChangeLog file.
* NEWS: List of important changes since 1.x releases.
* weather, weather.py: Implemented support for Python 3000 as
requested by ptchinster on behalf of Arch Linux, conditions/forecast
searches by latitude/longitude requested by Brandt Daniels, support
for newer NOAA forecasts pointed out by Darryl Mouck and Richard
Dooling, custom URIs requested by Michel Pelzer, international
weather stations requested by Milton Hubsher, and fixed a metric
conversion issue with negative values reported by Jochen Keil,
Michiel Appelman and Stefan Metzlaff. Thanks to everyone for your
input and assistance!
* Release 1.5.
* (all): Updated copyright notices for 2010.
* FAQ, INSTALL, LICENSE, README: Reformatted as ReStructuredText.
* FAQ: Updated to mention alternative sources for NOAA's stations
list, in case the recommended one is unavailable (thanks Celejar!).
* NEWS: Renamed to ChangeLog and refactored into GNU format.
* weather: Added some comment padding between the shebang line and
the copyright, so that distributions wishing to carry patches which
modify the interpreter path don't have to refresh them every year
when the copyright line changes in their context.
* weather, weather.1, weatherrc.5, weather.py: Added experimental
alert, atypes, aurl and zones options to support retrieval,
filtering and formatting of unexpired NWS severe weather advisories.
* weather.1, weatherrc.5: Minor cosmetic fixes to option
descriptions.
* weather.1, weatherrc.5, weather.py: Added imperial and metric
options to filter/convert display units (thanks to Andrew Carter for
this suggestion!).
* weather.py: Fixed a METAR parsing error which would trigger an
IndexError exception if the NWS didn't have a station description on
file (thanks to Celejar for reporting the bug!). Fixed METAR title
line parsing to look for human-readable city and state in the first
line--previous code stopped showing the city name after NWS made
slight format mods. Upped the version to 1.5.
* weatherrc: Additional PIE (Saint Petersburg, FL), PNC (Ponca City,
OK), and PNS (Pensacola, FL) aliases.
* Release 1.4.
* (all): Updated the copyright years for 2008 on some of the files
in the current release and added a copyright statement to any files
previously lacking one.
* LICENSE: Replaced the previous BSD-like license with the one used
by the OpenBSD project (modeled after the Internet Software
Consortium's, a two-clause BSD license removing language made
unnecessary by the Berne convention); this new license is
functionally identical to the old one, just more terse and openly
recognized.
* weather: Clarified function parameters in calls from the wrapper
script to ease future ABI changes in the underlying module.
* weather, weather.py: Some extra comments were added to the source,
indentation style was updated from tab characters to three-space,
and lines longer than 79 columns were refactored or otherwise split.
* weather.1, weather.5, weather.py: Added an flines option to allow
the maximum number of forecast output lines to be shortened. Added
furl and murl options to allow overriding of the default current
conditions and forecast data retrieval URLs. Added a headers option
to allow overriding the default list of header names for current
conditions data filtering. Added a quiet option to suppress the
preamble lines and indentation for both current conditions and
forecast output.
* weather.py: Replaced the hardcoded fallback default METAR station
ID and forecast city/state abbreviation with error messages to
minimize confusion when necessary values are omitted. Adjusted a
couple of hard-coded error message strings to be consistent with the
output format of the option_parser module. Switched from urllib to
urllib2 for retrieving data, providing a simpler means to detect and
report retrieval errors. Upped the version to 1.4.
* Release 1.3.
* FAQ: Update to clarify that specifying an id won't automatically
provide a city and st to get the accompanying forecast.
* weather: Provided a consistent means for relocating weather.py to
a private location; thanks to Mark Tran for pointing out a conflict
with pyweather in ArchLinux (and presumably other distros as well).
* weather.py: Upped the version to 1.3.