Commit d3d77a49 authored by Cédric Crettaz's avatar Cédric Crettaz 🖥

Correction of a bug in the DCA Carouge for weather.

parent 1610660b
......@@ -383,16 +383,19 @@ def collect():
:return:
"""
weather_data = get_data_from_weather_service()
filepath = os.path.join(COLLECTION_DIR,'{}_weather_raw_data.json'.format(int(time.time())))
if weather_data:
filepath = os.path.join(COLLECTION_DIR,'{}_weather_raw_data.json'.format(int(time.time())))
with open(filepath, encoding='utf-8', mode='w') as f:
json.dump(
obj=weather_data,
fp=f
)
logger.info("Dumping to FS {}".format(filepath))
with open(filepath, encoding='utf-8', mode='w') as f:
json.dump(
obj=weather_data,
fp=f
)
logger.info("Dumping to FS {}".format(filepath))
return filepath
return filepath
else:
return None
def main():
......@@ -401,15 +404,17 @@ def main():
while True:
logger.info("Querying external service for Weather data")
filepath = collect()
if filepath:
logger.info("Converting data to harmozined format")
data = convert_raw_to_weather_data_model(filepath)
logger.info("Converting data to harmozined format")
data = convert_raw_to_weather_data_model(filepath)
logger.info("Updating values of WeatherObserved in IoT Platform")
update_weather_observed_entity(data)
logger.info("Updating values of WeatherObserved in IoT Platform")
update_weather_observed_entity(data)
logger.info("Updated successfully WeatherObserved in IoT Platform")
time.sleep(POST_DATA_PERIOD)
logger.info("Updated successfully WeatherObserved in IoT Platform")
time.sleep(POST_DATA_PERIOD)
else:
time.sleep(POST_DATA_PERIOD)
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment