Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def hourly(data_dir):
with pywws.storage.pywws_context(data_dir) as context:
# localise application
pywws.localisation.set_application_language(context.params)
# get weather station data
pywws.logdata.DataLogger(context).log_data()
# do the processing
pywws.process.process_data(context)
# do tasks
pywws.regulartasks.RegularTasks(context).do_tasks()
return 0
logger.info("update: %s", idx.isoformat(' '))
elif count % 500 == 0:
logger.debug("update: %s", idx.isoformat(' '))
if data['wind_dir'] is not None and (data['wind_dir'] & 0x80):
data['wind_dir'] = None
raw_data[idx] = data
raw_data.flush()
# delete old format summary files
logger.warning('Deleting old summaries')
context.calib_data.clear()
context.hourly_data.clear()
context.daily_data.clear()
context.monthly_data.clear()
# create data summaries
logger.warning('Generating hourly and daily summaries')
pywws.process.process_data(context)
return 0
def live_log(data_dir):
# set up signal handlers
signal.signal(signal.SIGHUP, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
with pywws.storage.pywws_context(data_dir, live_logging=True) as context:
# localise application
pywws.localisation.set_application_language(context.params)
# create a DataLogger object
datalogger = pywws.logdata.DataLogger(context)
# create a RegularTasks object
tasks = pywws.regulartasks.RegularTasks(context)
try:
# fetch and process any new logged data
datalogger.log_data()
pywws.process.process_data(context)
# get live data
for data, logged in datalogger.live_data(
logged_only=(not tasks.has_live_tasks())):
if logged:
# process new data
pywws.process.process_data(context)
# do tasks
tasks.do_tasks()
else:
tasks.do_live(data)
except KeyboardInterrupt:
return 0
except NotImplementedError:
return 3
except Exception as ex:
logger.exception(ex)