From ad5adbee4af99da8d4aceb5e655b1f3c576fb4d1 Mon Sep 17 00:00:00 2001 From: xxm Date: Wed, 26 Aug 2026 14:50:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20fx=5Frate=5Fdaily=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=B1=87=E7=8E=87=E9=87=87=E9=9B=86cron(=E6=94=B6=E7=9B=98?= =?UTF-8?q?=E5=90=8E16:35=E9=94=81=E5=AE=9Afx=5Frate=E8=A1=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/fx_rate_daily.py | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 deploy/profile-scripts/fx_rate_daily.py diff --git a/deploy/profile-scripts/fx_rate_daily.py b/deploy/profile-scripts/fx_rate_daily.py new file mode 100644 index 00000000..86324057 --- /dev/null +++ b/deploy/profile-scripts/fx_rate_daily.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""fx_rate_daily.py — 每日汇率采集(收盘后锁定当日汇率) + +调度:每日 16:35(收盘后) +写入:fx_rate 表(is_active=1 的最新记录) +逻辑:调 hk_rate.refresh_rate() → API → 写 fx_rate 表 + 缓存 +""" +import os, sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +try: + from messenger import install_stdio_hook as _msh + _msh() +except Exception: + pass + +def main(): + print(f"[fx_rate_daily] {__import__('datetime').datetime.now():%Y-%m-%d %H:%M} 开始", flush=True) + try: + from hk_rate import refresh_rate + rate = refresh_rate() + print(f"[fx_rate_daily] 汇率刷新完成: HKD/CNY = {rate}", flush=True) + + # 验证 fx_rate 表已更新 + import sqlite3 + conn = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=10) + r = conn.execute( + "SELECT rate, source, created_at FROM fx_rate " + "WHERE currency_pair='HKD_CNY' AND is_active=1 ORDER BY id DESC LIMIT 1" + ).fetchone() + conn.close() + if r: + print(f"[fx_rate_daily] fx_rate 表确认: rate={r[0]} source={r[1]} {r[2]}", flush=True) + else: + print(f"[fx_rate_daily] ⚠️ fx_rate 表无 active 记录", flush=True) + except Exception as e: + print(f"[fx_rate_daily] ❌ 失败: {e}", flush=True) + sys.exit(1) + +if __name__ == "__main__": + main()