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-2010 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 get_bool = selections.get_bool
24 # this mode just lists the aliases defined in the config
25 if get_bool("list"): print weather.list_aliases(selections.config)
30 for argument in selections.arguments:
31 if get_bool("conditions", argument) or not (
32 get_bool("alert", argument) or get_bool("forecast", argument)
34 partial = weather.get_metar(
35 id=get("id", argument),
36 verbose=get_bool("verbose", argument),
37 quiet=get_bool("quiet", argument),
38 headers=get("headers", argument),
39 murl=get("murl", argument),
40 imperial=get_bool("imperial", argument),
41 metric=get_bool("metric", argument)
43 if partial: output += partial + "\n"
44 if get_bool("forecast", argument) or not (
45 get_bool("alert", argument) or get_bool("conditions", argument)
47 partial = weather.get_forecast(
48 city=get("city", argument),
49 st=get("st", argument),
50 verbose=get_bool("verbose", argument),
51 quiet=get_bool("quiet", argument),
52 flines=get("flines", argument),
53 furl=get("furl", argument),
54 imperial=get_bool("imperial", argument),
55 metric=get_bool("metric", argument)
57 if partial: output += partial + "\n"
58 if get_bool("alert", argument) or not (
59 get_bool("conditions", argument) or get_bool("forecast", argument)
62 for atype in get("atypes", argument).split(","):
63 for zone in get("zones", argument).split(","):
64 partial = weather.get_alert(
66 verbose=get_bool("verbose", argument),
67 quiet=get_bool("quiet", argument),
69 aurl=get("aurl", argument),
70 imperial=get_bool("imperial", argument),
71 metric=get_bool("metric", argument)
73 if partial: alert_text += partial + "\n"
74 if not alert_text: alert_text = "(no current alerts for your zones)\n"
76 output = output.strip()
77 if output: print( output )