diff --git a/data_platform/daily_all_update.py b/data_platform/daily_all_update.py index 78bbf944..08089f12 100644 --- a/data_platform/daily_all_update.py +++ b/data_platform/daily_all_update.py @@ -401,21 +401,45 @@ def run_daily_update(codes: List[str]) -> dict: continue data = None + source_used = "" first_attempt_failed = False + + # 主源:东方财富(amount真实,可拿多年历史) for attempt in range(MAX_RETRIES): try: - data = fetch_tencent_daily(code, next_day, today) + data = fetch_eastmoney_daily(code, next_day, today) if data is not None: + source_used = "eastmoney" break if attempt == 0: first_attempt_failed = True - except Exception as e: + except Exception: if attempt == 0: first_attempt_failed = True if attempt < MAX_RETRIES - 1: - time.sleep(1) - else: - logger.debug("日线 %s 失败: %s", code, e) + time.sleep(2) + + # 备源:腾讯(amount有时为0) + if data is None: + first_attempt_failed_backup = False + for attempt in range(MAX_RETRIES): + try: + data = fetch_tencent_daily(code, next_day, today) + if data is not None: + source_used = "tencent" + break + if attempt == 0: + first_attempt_failed_backup = True + except Exception: + if attempt == 0: + first_attempt_failed_backup = True + if attempt < MAX_RETRIES - 1: + time.sleep(1) + # 只有两个源都首次失败才算全局失败 + if first_attempt_failed and first_attempt_failed_backup: + first_attempt_failed = True + else: + first_attempt_failed = False # 全局源不可用检测 if not health.report(code, first_attempt_failed and data is None):