2 # distributions may wish to edit the above to refer to a specific interpreter
3 # path, such as #!/usr/bin/python
5 # Copyright (c) 2006-2024 Jeremy Stanley <fungi@yuggoth.org>. Permission to
6 # use, copy, modify, and distribute this software is granted under terms
7 # provided in the LICENSE file distributed with this software.
9 """Wrapper utility using the weather.py module."""
11 # added so distributors can consistently specify a private module location
12 private_module_path = None
13 if private_module_path:
15 sys.path.insert(1, private_module_path)
19 # initialize options and configs
20 selections = weather.Selections()
22 # this mode just lists the aliases defined in the config
23 if selections.get_bool("list"):
24 print( weather.list_aliases(selections.config) )
26 # this mode lists details of aliases defined in the config
27 elif selections.get_bool("longlist"):
28 print( weather.list_aliases(selections.config, detail=True) )
30 # this mode builds the correlation data files
31 elif selections.get_bool("build_sets"):
34 # if no arguments were provided
35 elif not selections.arguments:
38 # substitute defaults if we have any
39 if selections.config.has_option("default", "defargs"):
40 sys.argv += selections.config.get("default", "defargs").split(",")
41 selections = weather.Selections()
43 # otherwise be helpful
45 sys.argv += ("--help",)
46 selections = weather.Selections()
48 # these modes analyze correlations
49 if selections.get_bool("info"):
51 selections.arguments[0],
52 path=selections.get("setpath"),
53 info=selections.get_bool("info"),
55 selections.get_bool("cache") \
56 and selections.get_bool("cache_search")
58 cacheage=selections.getint("cacheage"),
59 cachedir=selections.get("cachedir")
65 for argument in selections.arguments:
66 if selections.get_bool("conditions", argument) or not (
67 selections.get_bool("alert", argument) \
68 or selections.get_bool("forecast", argument)
70 partial = weather.get_metar(
71 uri=selections.get("metar", argument),
72 verbose=selections.get_bool("verbose", argument),
73 quiet=selections.get_bool("quiet", argument),
74 headers=selections.get("headers", argument),
75 imperial=selections.get_bool("imperial", argument),
76 metric=selections.get_bool("metric", argument),
78 selections.get_bool("cache") \
79 and selections.get_bool("cache_data")
81 cacheage=selections.getint("cacheage"),
82 cachedir=selections.get("cachedir")
84 if partial: output += partial + "\n"
85 if selections.get_bool("forecast", argument) \
86 or selections.get_bool("alert", argument):
88 if selections.get_bool("alert", argument):
89 atypes = selections.get("atypes", argument).split(",")
92 if selections.get_bool("forecast", argument):
93 atypes = ["zone_forecast"] + atypes
95 partial = weather.get_alert(
96 uri=selections.get(atype, argument),
97 verbose=selections.get_bool("verbose", argument),
98 quiet=selections.get_bool("quiet", argument),
100 selections.get_bool("cache") \
101 and selections.get_bool("cache_data")
103 cacheage=selections.getint("cacheage"),
104 cachedir=selections.get("cachedir"),
105 delay=selections.getint("delay")
108 alert_text += "***** %s *****\n%s\n" % (
109 atype.replace("_", " ").title(),
113 alert_text = "(no current alerts for this zone)\n"
115 output = output.strip()
116 if output: print( output )