# 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-2024 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.
# 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"),
+ delay=selections.getint("delay")
+ )
+ 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 )