weather_00_collect_raw_weather_data_carouge.py 788 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env python3

"""
Dumps weather data to disk each POST_DATA_PERIOD seconds
"""

import os
import json
import time
import logging
from weather_api import *

logger = logging.getLogger()
logger.setLevel(logging.INFO)

logger.info("Starting to collect..")

COLLECTION_DIR = os.getenv('COLLECTION_DIR', default='.')
19
def collect():
20 21 22 23 24 25 26 27
    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())))
    with open(filepath, encoding='utf-8', mode='w') as f:
        json.dump(
            obj=weather_data,
            fp=f
28 29 30 31 32 33 34
        )

collect()
# Send updates in a loop
while True:
    time.sleep(POST_DATA_PERIOD)
    collect()