diff --git a/PSILARTEMP.py b/PSILARTEMP.py index b3fd6c1ab72109fd2ffdcdd12f80b7b150c0bcbf..6f7158ad563975e7872c36a894bd0b3caecf2d64 100755 --- a/PSILARTEMP.py +++ b/PSILARTEMP.py @@ -32,6 +32,7 @@ config = configparser.ConfigParser() config.read("PSILARTEMP.cfg") year = os.getenv("YEAR") +recurring_start_date = os.getenv("RECURRING_START_DATE") weatherdata_path = os.getenv("WEATHER_DATA_DIR") tmp_path = "tmp/" out_path = os.getenv("DATA_DIR") @@ -39,11 +40,17 @@ out_path = os.getenv("DATA_DIR") # TODO: Put timezone out in .env local_timezone = pytz.timezone("Europe/Oslo") +# 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: + print(f"Today is before the configured start time of {start_time}. Exiting.") + exit(0) + # """ # Calculate cumulated degree days above 5 degrees after 1st of April # Remove all values before April 1st subprocess.run( - f"cdo -selname,TM -seldate,{year}-04-01T00:00:00,{year}-12-31T00:00:00 {weatherdata_path}met_1_0km_nordic-{year}.nc {tmp_path}TM_from_april.nc", + f"cdo -selname,TM -seldate,{year}-{recurring_start_date}T00:00:00,{year}-12-31T00:00:00 {weatherdata_path}met_1_0km_nordic-{year}.nc {tmp_path}TM_from_april.nc", shell=True, ) # Subtracting 5 deg C from all cells diff --git a/env-sample b/env-sample index 03888741aadefd402ce984960ddf29f7f479cc30..e0f2cad3d82eff856d6ae045a5d097f0680e5ff2 100644 --- a/env-sample +++ b/env-sample @@ -2,6 +2,8 @@ # Year to run for YEAR=2024 +# Recurring start date (MM-DD) +RECURRING_START_DATE=04-01 # Where your application resides HOME_DIR=/home/foo/ # Path to the weather data