Imported from archive.
[weather.git] / weather
1 #!/usr/bin/env python
2
3 # weather version 1.4, http://fungi.yuggoth.org/weather/
4 # Copyright (c) 2006-2008 Jeremy Stanley <fungi@yuggoth.org>.
5 # Permission to use, copy, modify, and distribute this software is
6 # granted under terms provided in the LICENSE file distributed with
7 # this software.
8
9 """Wrapper utility using the weather.py module."""
10
11 # added so distributors can consistently specify a private module location
12 private_module_path = None
13 if private_module_path:
14    import sys
15    sys.path.insert(1, private_module_path)
16
17 import weather
18
19 # initialize options and configs
20 selections = weather.Selections()
21 get = selections.get
22 get_bool = selections.get_bool
23
24 # this mode just lists the aliases defined in the config
25 if get_bool("list"): print weather.list_aliases(selections.config)
26
27 # normal operation
28 else:
29    for argument in selections.arguments:
30       if get_bool("conditions", argument):
31          print weather.get_metar(
32             id=get("id", argument),
33             verbose=get_bool("verbose", argument),
34             quiet=get_bool("quiet", argument),
35             headers=get("headers", argument),
36             murl=get("murl", argument)
37             )
38       if not get_bool("conditions", argument) \
39          or get_bool("forecast", argument):
40          print weather.get_forecast(
41             city=get("city", argument),
42             st=get("st", argument),
43             verbose=get_bool("verbose", argument),
44             quiet=get_bool("quiet", argument),
45             flines=get("flines", argument),
46             furl=get("furl", argument)
47             )