Imported from archive.

* 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!
This commit is contained in:
Jeremy Stanley
2012-06-26 00:48:37 +00:00
parent 4d25a49d5a
commit 93f58b4538
20 changed files with 728634 additions and 1959 deletions
+93 -55
View File
@@ -2,7 +2,7 @@
# distributions may wish to edit the above to refer to a specific interpreter
# path, such as #!/usr/bin/python
# Copyright (c) 2006-2010 Jeremy Stanley <fungi@yuggoth.org>. Permission to
# Copyright (c) 2006-2012 Jeremy Stanley <fungi@yuggoth.org>. Permission to
# use, copy, modify, and distribute this software is granted under terms
# provided in the LICENSE file distributed with this software.
@@ -11,67 +11,105 @@
# added so distributors can consistently specify a private module location
private_module_path = None
if private_module_path:
import sys
sys.path.insert(1, private_module_path)
import sys
sys.path.insert(1, private_module_path)
import weather
# initialize options and configs
selections = weather.Selections()
get = selections.get
get_bool = selections.get_bool
# this mode just lists the aliases defined in the config
if get_bool("list"): print weather.list_aliases(selections.config)
if selections.get_bool("list"):
print( weather.list_aliases(selections.config) )
# this mode lists details of aliases defined in the config
elif selections.get_bool("longlist"):
print( weather.list_aliases(selections.config, detail=True) )
# this mode builds the correlation data files
elif selections.get_bool("build_sets"):
weather.correlate()
# if no arguments were provided
elif not selections.arguments:
import sys
# substitute defaults if we have any
if selections.config.has_option("default", "defargs"):
sys.argv += selections.config.get("default", "defargs").split(",")
selections = weather.Selections()
# otherwise be helpful
else:
sys.argv += ("--help",)
selections = weather.Selections()
# these modes analyze correlations
if selections.get_bool("info"):
weather.guess(
selections.arguments[0],
path=selections.get("setpath"),
info=selections.get_bool("info"),
cache_search=(
selections.get_bool("cache") \
and selections.get_bool("cache_search")
),
cacheage=selections.getint("cacheage"),
cachedir=selections.get("cachedir")
)
# normal operation
else:
output = ""
for argument in selections.arguments:
if get_bool("conditions", argument) or not (
get_bool("alert", argument) or get_bool("forecast", argument)
):
partial = weather.get_metar(
id=get("id", argument),
verbose=get_bool("verbose", argument),
quiet=get_bool("quiet", argument),
headers=get("headers", argument),
murl=get("murl", argument),
imperial=get_bool("imperial", argument),
metric=get_bool("metric", argument)
)
if partial: output += partial + "\n"
if get_bool("forecast", argument) or not (
get_bool("alert", argument) or get_bool("conditions", argument)
):
partial = weather.get_forecast(
city=get("city", argument),
st=get("st", argument),
verbose=get_bool("verbose", argument),
quiet=get_bool("quiet", argument),
flines=get("flines", argument),
furl=get("furl", argument),
imperial=get_bool("imperial", argument),
metric=get_bool("metric", argument)
)
if partial: output += partial + "\n"
if get_bool("alert", argument) or not (
get_bool("conditions", argument) or get_bool("forecast", argument)
):
alert_text = ""
for atype in get("atypes", argument).split(","):
for zone in get("zones", argument).split(","):
partial = weather.get_alert(
zone=zone,
verbose=get_bool("verbose", argument),
quiet=get_bool("quiet", argument),
atype=atype,
aurl=get("aurl", argument),
imperial=get_bool("imperial", argument),
metric=get_bool("metric", argument)
)
if partial: alert_text += partial + "\n"
if not alert_text: alert_text = "(no current alerts for your zones)\n"
output += alert_text
output = output.strip()
if output: print( output )
output = ""
for argument in selections.arguments:
if selections.get_bool("conditions", argument) or not (
selections.get_bool("alert", argument) \
or selections.get_bool("forecast", argument)
):
partial = weather.get_metar(
uri=selections.get("metar", argument),
verbose=selections.get_bool("verbose", argument),
quiet=selections.get_bool("quiet", argument),
headers=selections.get("headers", argument),
imperial=selections.get_bool("imperial", argument),
metric=selections.get_bool("metric", argument),
cache_data=(
selections.get_bool("cache") \
and selections.get_bool("cache_data")
),
cacheage=selections.getint("cacheage"),
cachedir=selections.get("cachedir")
)
if partial: output += partial + "\n"
if selections.get_bool("forecast", argument) \
or selections.get_bool("alert", argument):
alert_text = ""
if selections.get_bool("alert", argument):
atypes = selections.get("atypes", argument).split(",")
else:
atypes = []
if selections.get_bool("forecast", argument):
atypes = ["zone_forecast"] + atypes
for atype in atypes:
partial = weather.get_alert(
uri=selections.get(atype, argument),
verbose=selections.get_bool("verbose", argument),
quiet=selections.get_bool("quiet", argument),
cache_data=(
selections.get_bool("cache") \
and selections.get_bool("cache_data")
),
cacheage=selections.getint("cacheage"),
cachedir=selections.get("cachedir")
)
if partial:
alert_text += "***** %s *****\n%s\n" % (
atype.replace("_", " ").title(),
partial
)
if not alert_text:
alert_text = "(no current alerts for this zone)\n"
output += alert_text
output = output.strip()
if output: print( output )