1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#!/usr/bin/env python
# distributions may wish to edit the above to refer to a specific interpreter
# path, such as #!/usr/bin/python
# 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.
"""Wrapper utility using the weather.py module."""
# 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 weather
# initialize options and configs
selections = weather.Selections()
# this mode just lists the aliases defined in the 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 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 )
|