X-Git-Url: https://wylark.com/src/infoex-autowx.git/blobdiff_plain/56ad0a141fb31c3292f95c13863df79bf2435205..08c549c0c49fe81b581975e185c3a3afb5cd5907:/infoex-autowx.py?ds=inline diff --git a/infoex-autowx.py b/infoex-autowx.py index 442376b..598f24c 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -45,7 +45,7 @@ import zeep.transports __version__ = '2.0.0' log = logging.getLogger(__name__) -log.setLevel(logging.DEBUG) +log.setLevel(logging.NOTSET) try: from systemd.journal import JournalHandler @@ -58,39 +58,50 @@ except: handler = logging.StreamHandler(sys.stdout) log.addHandler(handler) -parser = OptionParser() +parser = OptionParser(version=__version__) parser.add_option("--config", dest="config", metavar="FILE", help="location of config file") +parser.add_option("--log-level", + dest="log_level", + default=None, + help="set the log level (debug, info, warning)") + parser.add_option("--dry-run", action="store_true", dest="dry_run", default=False, help="fetch data but don't upload to InfoEx") -parser.add_option("--version", - action="store_true", - dest="show_version", - default=False, - help="show program version and exit") - (options, args) = parser.parse_args() config = configparser.ConfigParser(allow_no_value=False) -if options.show_version: - print("%s - %s" % (os.path.basename(__file__), __version__)) - sys.exit(0) - if not options.config: - print("Please specify a configuration file via --config.") + parser.print_help() + print("\nPlease specify a configuration file via --config.") sys.exit(1) config.read(options.config) +# ugly, but passable +if options.log_level in [None, 'debug', 'info', 'warning']: + if options.log_level == 'debug': + log.setLevel(logging.DEBUG) + elif options.log_level == 'info': + log.setLevel(logging.INFO) + elif options.log_level == 'warning': + log.setLevel(logging.WARNING) + else: + log.setLevel(logging.NOTSET) +else: + parser.print_help() + print("\nPlease select an appropriate log level or remove the switch (--log-level).") + sys.exit(1) + log.debug('STARTING UP') try: @@ -169,7 +180,7 @@ except ValueError as exc: # # Also note that the current Auto Wx InfoEx documentation shows these # keys in a graphical table with the "index" beginning at 1, but here we -# are sanely indexing beginning at 0. +# sanely index beginning at 0. fmap = {} ; final_data = [None] * 29 fmap['Location UUID'] = 0 ; final_data[0] = infoex['location_uuid'] fmap['obDate'] = 1 ; final_data[1] = None @@ -312,9 +323,9 @@ elif data['provider'] == 'mesowest': # sort and isolate the most recent, see note above in NRCS for how and # why this is done # - # NOTE: Unlike in the NRCS case, the MesoWest API respones contains all + # NOTE: Unlike in the NRCS case, the MesoWest API response contains all # data (whereas with NRCS, we have to make a separate request for - # each element we want. This is nice for network efficiency but + # each element we want). This is nice for network efficiency but # it means we have to handle this part differently for each. # # NOTE: Also unlike NRCS, MesoWest provides more granular data; NRCS @@ -352,7 +363,7 @@ for elementCd in infoex['wx_data']: # any possible elementCds we may want are any other data # type than float. # - # Another possibility is to query the API with + # Another possibility is to query the API with # getStationElements and temporarily store the # storedUnitCd. But that's pretty network-intensive and # may not even be worth it if there's only e.g. one or two @@ -370,7 +381,6 @@ with open(infoex['csv_filename'], 'w') as f: f.close() if not options.dry_run: - # not a dry run with open(infoex['csv_filename'], 'rb') as f: log.debug("uploading FTP file '%s'" % (infoex['host'])) ftp = FTP(infoex['host'], infoex['uuid'], infoex['api_key'])