auto-sync: 2026-05-05 11:25:53

This commit is contained in:
cfdaily
2026-05-05 11:25:53 +08:00
parent 21933cc2bb
commit 1ec51f2a46
+7 -12
View File
@@ -92,14 +92,10 @@ def code_to_baostock(code: str) -> Tuple[str, str]:
def is_backfilled(parquet_path: Path) -> bool: def is_backfilled(parquet_path: Path) -> bool:
"""检查文件是否已经被BaoStock回补过(通过元数据标记)""" """检查文件是否已经被BaoStock回补过"""
if not parquet_path.exists(): # 用标记文件判断
return False marker = parquet_path.parent / f".{parquet_path.stem}.baostock"
try: return marker.exists()
df = pd.read_parquet(parquet_path)
return df.attrs.get("source") == "baostock"
except Exception:
return False
def load_progress() -> set: def load_progress() -> set:
@@ -167,9 +163,6 @@ def fetch_bs_15min(bs_code: str, start_date: str, end_date: str) -> Optional[pd.
if bad_ohlc.any(): if bad_ohlc.any():
df = df[~bad_ohlc] df = df[~bad_ohlc]
# 标记数据来源
df.attrs["source"] = "baostock"
return df if not df.empty else None return df if not df.empty else None
@@ -209,8 +202,10 @@ def backfill_one(code: str, start_date: str, end_date: str, force: bool = False)
# 写入新文件 # 写入新文件
try: try:
df_new = df_new.sort_values("day").reset_index(drop=True) df_new = df_new.sort_values("day").reset_index(drop=True)
# 保存时把attrs写入parquet metadata
df_new.to_parquet(parquet_path, index=False) df_new.to_parquet(parquet_path, index=False)
# 写标记文件
marker = parquet_path.parent / f".{parquet_path.stem}.baostock"
marker.write_text(datetime.now().isoformat())
return "ok", len(df_new) return "ok", len(df_new)
except Exception as e: except Exception as e:
logger.error("写入 %s 失败: %s", code, e) logger.error("写入 %s 失败: %s", code, e)