zt p commited on
Commit
552bc71
·
1 Parent(s): b879234

Adjust monitor daily notification timing

Browse files
pages/💸 空场防空转监控.py CHANGED
@@ -104,6 +104,11 @@ def parse_show_datetime(date_str, time_str):
104
  return None
105
 
106
 
 
 
 
 
 
107
  def extract_hall_number_raw(hall_name):
108
  """仅提取数字ID,用于API映射"""
109
  match = re.search(r'(\d+)', str(hall_name))
@@ -481,21 +486,15 @@ class PlaybackMonitor:
481
 
482
  def _run_loop(self):
483
  self.log("🚀 空场防空转监控服务已启动")
484
- is_first_run = True
485
 
486
  while True:
487
  try:
488
  now = get_beijing_now()
489
  biz_date = get_business_date()
490
  today_str = now.strftime("%Y-%m-%d")
491
-
492
- if is_first_run:
493
- if now.time() >= dt_time(9, 0):
494
- self.last_daily_report_date = today_str
495
- self.log(f"🟡 首次运行,跳过当日即时通知: {today_str}")
496
- else:
497
- self.log("🟡 首次运行完成初始化,等待 09:00 后再发送每日报告")
498
- is_first_run = False
499
 
500
  # --- 初始化与日期变更 ---
501
  need_refresh = False
@@ -524,7 +523,7 @@ class PlaybackMonitor:
524
  time.sleep(300)
525
  continue
526
 
527
- if now.time() >= dt_time(9, 0) and self.last_daily_report_date != today_str and self.daily_schedule_cache is not None:
528
  try:
529
  d_obj = datetime.strptime(biz_date, "%Y-%m-%d")
530
  date_cn = f"{d_obj.year}年{d_obj.month}月{d_obj.day}日"
 
104
  return None
105
 
106
 
107
+ def did_cross_fixed_time(previous_time, current_time, target_time):
108
+ target_dt = datetime.combine(current_time.date(), target_time)
109
+ return previous_time < target_dt <= current_time
110
+
111
+
112
  def extract_hall_number_raw(hall_name):
113
  """仅提取数字ID,用于API映射"""
114
  match = re.search(r'(\d+)', str(hall_name))
 
486
 
487
  def _run_loop(self):
488
  self.log("🚀 空场防空转监控服务已启动")
489
+ last_loop_time = get_beijing_now()
490
 
491
  while True:
492
  try:
493
  now = get_beijing_now()
494
  biz_date = get_business_date()
495
  today_str = now.strftime("%Y-%m-%d")
496
+ should_send_daily_report = did_cross_fixed_time(last_loop_time, now, dt_time(9, 0))
497
+ last_loop_time = now
 
 
 
 
 
 
498
 
499
  # --- 初始化与日期变更 ---
500
  need_refresh = False
 
523
  time.sleep(300)
524
  continue
525
 
526
+ if should_send_daily_report and self.last_daily_report_date != today_str and self.daily_schedule_cache is not None:
527
  try:
528
  d_obj = datetime.strptime(biz_date, "%Y-%m-%d")
529
  date_cn = f"{d_obj.year}年{d_obj.month}月{d_obj.day}日"
pages/📢 突发购票监控.py CHANGED
@@ -65,6 +65,11 @@ def parse_show_datetime(date_str, time_str):
65
  return None
66
 
67
 
 
 
 
 
 
68
  def simplify_hall_name(raw_name):
69
  """
70
  影厅名称简化
@@ -269,24 +274,18 @@ class CinemaMonitor:
269
 
270
  def _run_loop(self):
271
  self.log("🚀 突发购票监控服务已启动")
272
- is_first_run = True
273
 
274
  while True:
275
  try:
276
  now = get_beijing_now()
277
  biz_date = get_business_date()
278
  today_str = now.strftime("%Y-%m-%d")
 
 
279
 
280
- if is_first_run:
281
- if now.time() >= dt_time(9, 0):
282
- self.last_daily_report_date = today_str
283
- self.log(f"🟡 首次运行,跳过当日即时通知: {today_str}")
284
- else:
285
- self.log("🟡 首次运行完成初始化,等待 09:00 后再发送每日报告")
286
- is_first_run = False
287
-
288
- # --- 每日健康检查 (09:00 后发送一次) ---
289
- if now.time() >= dt_time(9, 0) and self.last_daily_report_date != today_str:
290
  report_date_str = now.strftime("%Y年%m月%d日")
291
  self.log(f"🔔 发送每日统计报告: {today_str}")
292
 
@@ -496,4 +495,4 @@ def main():
496
 
497
 
498
  if __name__ == "__main__":
499
- main()
 
65
  return None
66
 
67
 
68
+ def did_cross_fixed_time(previous_time, current_time, target_time):
69
+ target_dt = datetime.combine(current_time.date(), target_time)
70
+ return previous_time < target_dt <= current_time
71
+
72
+
73
  def simplify_hall_name(raw_name):
74
  """
75
  影厅名称简化
 
274
 
275
  def _run_loop(self):
276
  self.log("🚀 突发购票监控服务已启动")
277
+ last_loop_time = get_beijing_now()
278
 
279
  while True:
280
  try:
281
  now = get_beijing_now()
282
  biz_date = get_business_date()
283
  today_str = now.strftime("%Y-%m-%d")
284
+ should_send_daily_report = did_cross_fixed_time(last_loop_time, now, dt_time(9, 0))
285
+ last_loop_time = now
286
 
287
+ # --- 每日健康检查 (固定 09:00 发送一次) ---
288
+ if should_send_daily_report and self.last_daily_report_date != today_str:
 
 
 
 
 
 
 
 
289
  report_date_str = now.strftime("%Y年%m月%d日")
290
  self.log(f"🔔 发送每日统计报告: {today_str}")
291
 
 
495
 
496
 
497
  if __name__ == "__main__":
498
+ main()
pages/📨 排片检查与 TMS 内容核对监控.py CHANGED
@@ -96,6 +96,11 @@ def get_check_date_range(base_date=None):
96
  return today, end_date
97
 
98
 
 
 
 
 
 
99
  def default_monitor_state():
100
  return {
101
  "last_completed_date": "",
@@ -1045,15 +1050,19 @@ class DailyTMSSummaryMonitor:
1045
 
1046
  def _run_loop(self):
1047
  self.log("🕤 排片检查与 TMS 内容核对监控已启动")
 
 
1048
  while True:
1049
  try:
1050
  now = get_beijing_now()
1051
  today_str = now.strftime("%Y-%m-%d")
 
 
1052
  state = load_monitor_state()
1053
  self.last_state = state
1054
  today_run_time = datetime.combine(now.date(), dt_time(9, 55))
1055
 
1056
- if state.get("last_completed_date") != today_str and now >= today_run_time:
1057
  self._execute_today_check()
1058
  time.sleep(5)
1059
  continue
@@ -1061,11 +1070,14 @@ class DailyTMSSummaryMonitor:
1061
  if state.get("last_completed_date") == today_str:
1062
  self.status_text = "已完成"
1063
  next_run_dt = datetime.combine(now.date() + timedelta(days=1), dt_time(9, 55))
 
 
 
1064
  else:
1065
  self.status_text = "未完成"
1066
- next_run_dt = today_run_time if now < today_run_time else now
1067
 
1068
- self.next_run_str = format_datetime_text(next_run_dt if next_run_dt > now else datetime.combine(now.date() + timedelta(days=1), dt_time(9, 55)))
1069
  time.sleep(30 if state.get("last_completed_date") != today_str and now < today_run_time else 60)
1070
  except Exception as exc:
1071
  self.log(f"❌ 主循环异常:{exc}")
 
96
  return today, end_date
97
 
98
 
99
+ def did_cross_fixed_time(previous_time, current_time, target_time):
100
+ target_dt = datetime.combine(current_time.date(), target_time)
101
+ return previous_time < target_dt <= current_time
102
+
103
+
104
  def default_monitor_state():
105
  return {
106
  "last_completed_date": "",
 
1050
 
1051
  def _run_loop(self):
1052
  self.log("🕤 排片检查与 TMS 内容核对监控已启动")
1053
+ last_loop_time = get_beijing_now()
1054
+
1055
  while True:
1056
  try:
1057
  now = get_beijing_now()
1058
  today_str = now.strftime("%Y-%m-%d")
1059
+ should_run_today = did_cross_fixed_time(last_loop_time, now, dt_time(9, 55))
1060
+ last_loop_time = now
1061
  state = load_monitor_state()
1062
  self.last_state = state
1063
  today_run_time = datetime.combine(now.date(), dt_time(9, 55))
1064
 
1065
+ if state.get("last_completed_date") != today_str and should_run_today:
1066
  self._execute_today_check()
1067
  time.sleep(5)
1068
  continue
 
1070
  if state.get("last_completed_date") == today_str:
1071
  self.status_text = "已完成"
1072
  next_run_dt = datetime.combine(now.date() + timedelta(days=1), dt_time(9, 55))
1073
+ elif now >= today_run_time:
1074
+ self.status_text = "等待下次固定时间"
1075
+ next_run_dt = datetime.combine(now.date() + timedelta(days=1), dt_time(9, 55))
1076
  else:
1077
  self.status_text = "未完成"
1078
+ next_run_dt = today_run_time
1079
 
1080
+ self.next_run_str = format_datetime_text(next_run_dt)
1081
  time.sleep(30 if state.get("last_completed_date") != today_str and now < today_run_time else 60)
1082
  except Exception as exc:
1083
  self.log(f"❌ 主循环异常:{exc}")