def find_last_stored_measurement(path): years = get_directories(path) years.sort(reverse=True) for y in years: months = get_directories(path + os.path.sep + y) months.sort(reverse=True) for m in months: dfiles = get_data_file_names(path + os.path.sep + y + os.path.sep + m) dfiles.sort(reverse=True) for df in dfiles: year = int(y) month = int(m) d = int(os.path.splitext(df)[0]) dt = date(year, month, d) day = create_day_from_file(path, dt) if len(day.hourly_records) > 0: tm = day.hourly_records[-1].time return datetime(year, month, d, tm.hour, tm.minute) return NULL_DATE
lsm = find_last_stored_measurement(main_config.data_path) logging.info('Last stored record:' + lsm.__str__()) communicator = Communicator(main_config.port,baudrate=main_config.baudrate, altitude=main_config.station_altitude) communicator.wake_up() communicator.test_comm() records = communicator.get_archive_data(lsm) communicator.close_comm_port() days = [] if len(records) > 0: for r in records: day = find_day(days, r.date) if day is None: day = create_day_from_file(main_config.data_path, r.date) if day is None: day = Day(r.date) days.append(day) logging.info(r.to_output_string(day.output_columns)) day.append(r) for d in days: logging.info(d.header_string()) d.sort_records() d.save_to_file(main_config.data_path) logging.info("Writing daily data for: %s" % (d.date.isoformat())) else: logging.info('No new records received')