X-Git-Url: https://wylark.com/src/infoex-autowx.git/blobdiff_plain/f26265c377d65418b713040565917fb8cc8e878a..56ad0a141fb31c3292f95c13863df79bf2435205:/infoex-autowx.py?ds=inline diff --git a/infoex-autowx.py b/infoex-autowx.py index 57fef27..442376b 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -42,6 +42,8 @@ import zeep import zeep.cache import zeep.transports +__version__ = '2.0.0' + log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) @@ -69,10 +71,20 @@ parser.add_option("--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.") sys.exit(1) @@ -112,6 +124,11 @@ try: 'PREC' # PRECIPITATION ACCUMULATION (in) ] + # XXX: For NRCS, we're manually overriding units for now! Once + # unit conversion is supported for NRCS, REMOVE THIS! + if 'units' not in data: + data['units'] = 'imperial' + if data['provider'] == 'mesowest': data['source'] = 'https://api.synopticdata.com/v2/stations/timeseries' data['station_id'] = config['station']['station_id'] @@ -192,10 +209,35 @@ if data['provider'] == 'nrcs': iemap['PREC'] = 'precipitationGauge' iemap['TOBS'] = 'tempPres' iemap['SNWD'] = 'hS' + iemap['PRES'] = 'baro' + iemap['RHUM'] = 'rH' + iemap['WSPD'] = 'windSpeedNum' + iemap['WDIR'] = 'windDirectionNum' + # unsupported by NRCS: + # windGustSpeedNum elif data['provider'] == 'mesowest': iemap['precip_accum'] = 'precipitationGauge' iemap['air_temp'] = 'tempPres' iemap['snow_depth'] = 'hS' + iemap['pressure'] = 'baro' + iemap['relative_humidity'] = 'rH' + iemap['wind_speed'] = 'windSpeedNum' + iemap['wind_direction'] = 'windDirectionNum' + iemap['wind_gust'] = 'windGustSpeedNum' + +# override units if user selected metric +# +# NOTE: to update this, use the fmap<->final_data mapping laid out above +# +# NOTE: this only 'works' with MesoWest for now, as the MesoWest API +# itself handles the unit conversion; in the future, we will also +# support NRCS unit conversion, but this must be done by this +# program. +if data['units'] == 'metric': + final_data[fmap['tempPresUnit']] = 'C' + final_data[fmap['hsUnit']] = 'm' + final_data[fmap['windSpeedUnit']] = 'm/s' + final_data[fmap['windGustSpeedNumUnit']] = 'm/s' # floor time to nearest hour dt = datetime.datetime.now()