X-Git-Url: https://wylark.com/src/infoex-autowx.git/blobdiff_plain/63610f54bdd9528db44d38dd3564724e8c72c063..c3f872e24d2f52b3cfaf441dfa6c5d2174a273fc:/infoex-autowx.py?ds=inline diff --git a/infoex-autowx.py b/infoex-autowx.py index 1844d45..c3144a4 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -43,7 +43,7 @@ import zeep import zeep.cache import zeep.transports -__version__ = '3.2.1' +__version__ = '3.2.3' LOG = logging.getLogger(__name__) LOG.setLevel(logging.NOTSET) @@ -156,8 +156,9 @@ def setup_logging(log_level): # fallback to stdout handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(asctime)s.%(msecs)03d ' - '%(levelname)s %(module)s - %(funcName)s: %(message)s', - '%Y-%m-%d %H:%M:%S') + '%(levelname)s %(module)s - ' + '%(funcName)s: %(message)s', + '%Y-%m-%d %H:%M:%S') handler.setFormatter(formatter) LOG.addHandler(handler) @@ -275,6 +276,9 @@ def main(): LOG.warning("BAD KEY wx_data['%s']", element_cd) continue + if infoex['wx_data'][element_cd] is None: + continue + # do the conversion before the rounding if station['provider'] == 'nrcs' and station['units'] == 'metric': infoex['wx_data'][element_cd] = convert_nrcs_units_to_metric(element_cd, infoex['wx_data'][element_cd]) @@ -286,11 +290,9 @@ def main(): # direction, wind gust, snow depth # 1 decimal place: air temp, baro # Avoid transforming None values - if infoex['wx_data'][element_cd] is None: - continue - elif element_cd in ['wind_speed', 'WSPD', 'wind_direction', - 'RHUM', 'relative_humidity', 'WDIR', - 'wind_gust', 'SNWD', 'snow_depth']: + if element_cd in ['wind_speed', 'WSPD', 'wind_direction', + 'RHUM', 'relative_humidity', 'WDIR', + 'wind_gust', 'SNWD', 'snow_depth']: infoex['wx_data'][element_cd] = round(infoex['wx_data'][element_cd]) elif element_cd in ['TOBS', 'air_temp', 'PRES', 'pressure']: infoex['wx_data'][element_cd] = round(infoex['wx_data'][element_cd], 1) @@ -526,6 +528,10 @@ def get_mesowest_data(begin, end, station): # we want mph if element_cd in ('wind_speed', 'wind_gust'): remote_data[element_cd] = kn_to_mph(remote_data[element_cd]) + + # mesowest provides HS in mm, not cm; we want cm + if element_cd == 'snow_depth' and station['units'] == 'metric': + remote_data[element_cd] = mm_to_cm(remote_data[element_cd]) else: remote_data[element_cd] = None else: @@ -623,5 +629,9 @@ def kn_to_mph(kn): """convert knots to miles per hour""" return kn * 1.150779 +def mm_to_cm(mm): + """convert millimeters to centimetrs""" + return mm / 10.0 + if __name__ == "__main__": sys.exit(main())