diff --git a/PSILARTEMP.py b/PSILARTEMP.py index 629a7756d9f9dccedb01b80a19c978a01d5fa30d..56c97ecb72e715c6798abc5905d454eb1a5ac3f0 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 5ddfa378f9837cbc935fa2cddc480a2d8ebbe3c2..79ff7721de9931921541507fe5cf5bb8e99e309c 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 7eea5788ece57b669f8bbe23e59d1579a80a3a5a..0e993577f4fe5d66c6c3c240befcc9be9e06ce04 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