X-Git-Url: https://www.yuggoth.org/gitweb?p=weather.git;a=blobdiff_plain;f=weather;h=67a13c8179a155c6def8237bb8a1d432108404dc;hp=5e620b8c39b70e6e110802e2bccd399bd4e6b291;hb=a33dd24ec1503c62f10587709e9b9a260972626b;hpb=8349654b7c627448b1e56c2943234895724d7857 diff --git a/weather b/weather index 5e620b8..67a13c8 100755 --- a/weather +++ b/weather @@ -1,47 +1,115 @@ #!/usr/bin/env python +# distributions may wish to edit the above to refer to a specific interpreter +# path, such as #!/usr/bin/python -# weather version 1.4, http://fungi.yuggoth.org/weather/ -# Copyright (c) 2006-2008 Jeremy Stanley . -# Permission to use, copy, modify, and distribute this software is -# granted under terms provided in the LICENSE file distributed with -# this software. +# Copyright (c) 2006-2012 Jeremy Stanley . 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 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: - for argument in selections.arguments: - if get_bool("conditions", argument): - print 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) - ) - if not get_bool("conditions", argument) \ - or get_bool("forecast", argument): - print 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) + 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 )