From d2d9391f16228ad51409428e852ec274709b9e54 Mon Sep 17 00:00:00 2001 From: webgisdeveloper Date: Wed, 9 Nov 2022 21:41:51 -0500 Subject: [PATCH] #41 check if it is too early to process --- HWRF_tool.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/HWRF_tool.py b/HWRF_tool.py index cb18280..0c6ae85 100644 --- a/HWRF_tool.py +++ b/HWRF_tool.py @@ -40,6 +40,20 @@ def check_status(adate): return processed +def check_hours(adate): + """ check if it is too early to process""" + # adate in YYYYMMDDHH + TIME_DELDAY = 8 #hours + from datetime import datetime + ct = datetime.now() + da = datetime.strptime(adate,"%Y%m%d%H") + delta = ct - da + dhours = int(delta.total_seconds() / 3600) + if dhours > TIME_DELDAY: + return False + else: + return True + def generate_procesing_list(): """ generate the processing list""" @@ -71,6 +85,9 @@ def generate_procesing_list(): a_entry = key + hhstr if check_status(a_entry): continue + # check if it is too early to process the data + if check_hours(a_entry): + continue dataurllist[a_entry] = os.path.join(hosturl,fstr) return dataurllist @@ -260,8 +277,8 @@ def HWRF_cron(): # get date list datelist = generate_procesing_list() # for debug - #print(datelist) - #sys.exit() + print(datelist) + sys.exit() if len(datelist) == 0: logging.info("no new data to process!")