From 9d847fb6084bcebf18125c31283e4d63f4a07ef8 Mon Sep 17 00:00:00 2001 From: Lene Wasskog <lene.wasskog@nibio.no> Date: Wed, 26 Feb 2025 10:39:39 +0100 Subject: [PATCH] feat: Local TZ as env var, use it for checking today. Update docs. --- PSILARTEMP.py | 8 +++----- README.md | 4 ++++ env-sample | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/PSILARTEMP.py b/PSILARTEMP.py index 629a775..56c97ec 100755 --- a/PSILARTEMP.py +++ b/PSILARTEMP.py @@ -33,7 +33,8 @@ load_dotenv() config = configparser.ConfigParser() config.read("PSILARTEMP.cfg") -today = datetime.now().date() +local_timezone = pytz.timezone(os.getenv("LOCAL_TIMEZONE")) +today = datetime.now(local_timezone).date() if len(sys.argv) > 1: year = int(sys.argv[1]) else: @@ -46,9 +47,6 @@ home_dir = os.getenv("HOME_DIR") out_path = f'{os.getenv("DATA_DIR")}{year}/' os.makedirs(out_path, exist_ok=True) -# TODO: Put timezone out in .env -local_timezone = pytz.timezone("Europe/Oslo") - # Ensure that model is not run for future year if year > today.year: print(f"Cannot run model for future year ({year}). Quit.") @@ -56,7 +54,7 @@ if year > today.year: # If we are before the recurring start date, exit nicely start_time = datetime.strptime(f"{year}-{recurring_start_date}","%Y-%m-%d") -if datetime.now() <= start_time: +if today <= start_time: print(f"Today is before the configured start time of {start_time}. Exiting.") exit(0) diff --git a/README.md b/README.md index 5ddfa37..79ff772 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,10 @@ The model (as per 2023-11-14) assumes that a weather data file named `met_1_0km_ It is required that you have set the following environment variables: ```bash +# Recurring start date (MM-DD) +RECURRING_START_DATE=04-01 +# Local time zone +LOCAL_TIMEZONE=Europe/Oslo # Where your application resides HOME_DIR=/home/foo/PSILARTEMP/ # Path to the weather data diff --git a/env-sample b/env-sample index 7eea578..0e99357 100644 --- a/env-sample +++ b/env-sample @@ -2,6 +2,8 @@ # Recurring start date (MM-DD) RECURRING_START_DATE=04-01 +# Local time zone +LOCAL_TIMEZONE=Europe/Oslo # Where your application resides HOME_DIR=/home/foo/PSILARTEMP/ # Path to the weather data -- GitLab