From: Alexander Vasarab Date: Thu, 2 Jul 2020 18:33:39 +0000 (-0700) Subject: Free a few more routines from main () X-Git-Tag: v2.0.1^2~1^2 X-Git-Url: https://wylark.com/src/infoex-autowx.git/commitdiff_plain/517f048d9255bb05dc8a4fc04aef3bd0859ed74f?ds=sidebyside Free a few more routines from main () --- diff --git a/infoex-autowx.py b/infoex-autowx.py index bb93eef..48a9063 100755 --- a/infoex-autowx.py +++ b/infoex-autowx.py @@ -193,25 +193,10 @@ def main(): iemap = setup_infoex_counterparts_mapping(station['provider']) # 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 station['units'] == 'metric': - final_data[fmap['tempPresUnit']] = 'C' - final_data[fmap['hsUnit']] = 'm' - final_data[fmap['windSpeedUnit']] = 'm/s' - final_data[fmap['windGustSpeedNumUnit']] = 'm/s' + final_data = switch_units_to_metric(final_data, fmap) - # floor time to nearest hour - dt = datetime.datetime.now() - end_date = dt - datetime.timedelta(minutes=dt.minute % 60, - seconds=dt.second, - microseconds=dt.microsecond) - begin_date = end_date - datetime.timedelta(hours=3) + (begin_date, end_date) = setup_time_values() # get the data LOG.debug("Getting %s data from %s to %s" % (str(station['desired_data']), @@ -432,6 +417,23 @@ def get_mesowest_data(begin, end, station): return remote_data +def switch_units_to_metric(data_map, mapping): + """replace units with metric counterparts""" + + # NOTE: to update this, use the fmap<->final_data mapping laid out + # in setup_infoex_fields_mapping () + # + # 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. + data_map[mapping['tempPresUnit']] = 'C' + data_map[mapping['hsUnit']] = 'm' + data_map[mapping['windSpeedUnit']] = 'm/s' + data_map[mapping['windGustSpeedNumUnit']] = 'm/s' + + return data_map + # CSV operations def write_local_csv(path_to_file, data): """Write the specified CSV file to disk""" @@ -455,5 +457,16 @@ def upload_csv(path_to_file, infoex_data): file_object.close() os.remove(path_to_file) +# other miscellaneous routines +def setup_time_values(): + """establish time bounds of data request(s)""" + # floor time to nearest hour + dt = datetime.datetime.now() + end_date = dt - datetime.timedelta(minutes=dt.minute % 60, + seconds=dt.second, + microseconds=dt.microsecond) + begin_date = end_date - datetime.timedelta(hours=3) + return (begin_date, end_date) + if __name__ == "__main__": sys.exit(main())