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']),
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"""
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())