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

Correction of a bug in the DCA Carouge for weather.

parent 1610660b
...@@ -383,16 +383,19 @@ def collect(): ...@@ -383,16 +383,19 @@ def collect():
:return: :return:
""" """
weather_data = get_data_from_weather_service() 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: with open(filepath, encoding='utf-8', mode='w') as f:
json.dump( json.dump(
obj=weather_data, obj=weather_data,
fp=f fp=f
) )
logger.info("Dumping to FS {}".format(filepath)) logger.info("Dumping to FS {}".format(filepath))
return filepath return filepath
else:
return None
def main(): def main():
...@@ -401,15 +404,17 @@ def main(): ...@@ -401,15 +404,17 @@ def main():
while True: while True:
logger.info("Querying external service for Weather data") logger.info("Querying external service for Weather data")
filepath = collect() 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") logger.info("Updating values of WeatherObserved in IoT Platform")
data = convert_raw_to_weather_data_model(filepath) update_weather_observed_entity(data)
logger.info("Updating values of WeatherObserved in IoT Platform") logger.info("Updated successfully WeatherObserved in IoT Platform")
update_weather_observed_entity(data) time.sleep(POST_DATA_PERIOD)
else:
logger.info("Updated successfully WeatherObserved in IoT Platform") time.sleep(POST_DATA_PERIOD)
time.sleep(POST_DATA_PERIOD)
if __name__ == "__main__": if __name__ == "__main__":
......
Supports Markdown
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