#!/usr/bin/env python3"""Dumps weather data to disk each POST_DATA_PERIOD seconds"""importosimportjsonimporttimeimportloggingfromweather_apiimport*logger=logging.getLogger()logger.setLevel(logging.INFO)logger.info("Starting to collect..")COLLECTION_DIR=os.getenv('COLLECTION_DIR',default='.')# Send updates in a loopwhileTrue:time.sleep(POST_DATA_PERIOD)logger.info("Querying service..")weather_data=get_data_from_weather_service()logger.info("Dumping to disk..")filepath=os.path.join(COLLECTION_DIR,'{}_weather_raw_data.json'.format(int(time.time())))withopen(filepath,encoding='utf-8',mode='w')asf:json.dump(obj=weather_data,fp=f)