Skip to content
Snippets Groups Projects
scheduler.py 957 B
Newer Older
import json
import time
import schedule

from map_handler.get_measurements import get_measurements
from server.consts import LAKE_RELATIONS_PATH


def update_all_measurements(lake_names: list):
    """Loops through all lake names and calls get_measurements() on each lake"""
    for lake in lake_names:
        get_measurements(lake)


def update_scheduler():
    """Schedules the updating of all maps every three days"""
    print("Updating all lake data. This may take some time...")

    # Parse all lake names to a list
    with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r') as file:
        lake_names = json.load(file)

    # Run update_all_measurements on startup
    update_all_measurements(lake_names)

    # Schedule the updating of all maps every three days
    schedule.every(3).days.do(update_all_measurements(lake_names))

    # Keep scheduler running indefinitely
    while True:
        schedule.run_pending()
        time.sleep(1)