V1
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# 导入数据获取模块的函数
|
||||
from get_etf_data import load_cache, CACHE_FILE, CACHE_DAYS, FUND_CODE,get_etf_data
|
||||
|
||||
# 导入推送模块的函数
|
||||
from gotify import push_gotify
|
||||
|
||||
|
||||
def format_cache_message(cache_data):
|
||||
"""格式化缓存数据为消息内容"""
|
||||
if not cache_data:
|
||||
return "⚠️ 暂无缓存数据"
|
||||
|
||||
# 按日期排序(最近的数据在前)
|
||||
sorted_dates = sorted(cache_data.keys(), reverse=True)
|
||||
|
||||
message_lines = []
|
||||
for date in sorted_dates:
|
||||
data = cache_data[date]
|
||||
line = (
|
||||
f"📅 {data['data_date'][:10]}\n"
|
||||
f" 成交额:{data['turnover_yi']:,.2f} 亿元\n"
|
||||
f" 总份额:{data['share_yi']:,.2f} 亿份"
|
||||
)
|
||||
message_lines.append(line)
|
||||
|
||||
return "\n\n".join(message_lines)
|
||||
|
||||
|
||||
def send_cache_notification():
|
||||
"""发送缓存数据通知"""
|
||||
get_etf_data()
|
||||
|
||||
# 加载缓存
|
||||
cache_data = load_cache()
|
||||
|
||||
if not cache_data:
|
||||
push_gotify(
|
||||
title="⚠️ ETF 数据通知",
|
||||
message="暂无缓存数据,请先运行 get_etf_data.py 获取数据",
|
||||
priority=5
|
||||
)
|
||||
return
|
||||
|
||||
# 统计数据
|
||||
total_days = len(cache_data)
|
||||
latest_date = max(cache_data.keys())
|
||||
latest_data = cache_data[latest_date]
|
||||
|
||||
# 生成标题
|
||||
title = f"📊 ETF 数据报告 ({FUND_CODE})"
|
||||
|
||||
# 生成消息内容
|
||||
message = (
|
||||
f"📈 缓存天数:{total_days} 天\n"
|
||||
f"🕐 最新数据:{latest_date}\n"
|
||||
f"💰 成交额:{latest_data['turnover_yi']:,.2f} 亿元\n"
|
||||
f"📦 总份额:{latest_data['share_yi']:,.2f} 亿份\n\n"
|
||||
f"{'='*10}\n"
|
||||
f"{format_cache_message(cache_data)}"
|
||||
)
|
||||
|
||||
# 发送推送
|
||||
push_gotify(
|
||||
title=title,
|
||||
message=message,
|
||||
priority=3
|
||||
)
|
||||
|
||||
print(f"✅ 已发送 {total_days} 天的缓存数据通知")
|
||||
|
||||
|
||||
# ---------------------- 程序入口 ----------------------
|
||||
if __name__ == "__main__":
|
||||
send_cache_notification()
|
||||
Reference in New Issue
Block a user