确认每天的同步时间

This commit is contained in:
朱思南 2026-03-09 16:56:39 +08:00
parent d67e85ac87
commit 77409ec0bb
3 changed files with 30 additions and 14 deletions

View File

@ -48,8 +48,8 @@ class SWIndustryHeatTracker:
} }
# 初始化数据库表 # 初始化数据库表
if self.db_config: # if self.db_config:
self._init_database() # self._init_database()
def _init_database(self): def _init_database(self):
"""初始化MySQL数据库和表""" """初始化MySQL数据库和表"""
@ -104,6 +104,14 @@ class SWIndustryHeatTracker:
return set(dates) return set(dates)
def is_trading_day(self, date=None):
"""判断是否为交易日"""
if date is None:
date = datetime.now()
if isinstance(date, datetime):
date = date.strftime('%Y-%m-%d')
return date in self.trading_dates
def _update_calendar_cache(self, cache_file): def _update_calendar_cache(self, cache_file):
"""更新交易日历缓存""" """更新交易日历缓存"""
print("正在更新交易日历...") print("正在更新交易日历...")
@ -352,6 +360,18 @@ class SWIndustryHeatTracker:
f"量比:{row['volume_ratio']:4.2f} | " f"量比:{row['volume_ratio']:4.2f} | "
f"动量:{row['momentum']:.0%}") f"动量:{row['momentum']:.0%}")
# 打印冷门板块后10名
print(f"\n❄️ 冷门板块 (后10名):")
print("-"*80)
bottom10 = heat_df.tail(10)
for _, row in bottom10.iterrows():
print(f"{row['rank']:2d}. {row['name']:8s} | "
f"热度:{row['heat_score']:5.1f}({row['heat_level']}) | "
f"收益:{row['total_return']:+6.2f}% | "
f"换手:{row['avg_turnover']:5.2f}% | "
f"量比:{row['volume_ratio']:4.2f} | "
f"动量:{row['momentum']:.0%}")
# 保存数据部分 # 保存数据部分
if save: if save:
today = datetime.now().strftime('%Y-%m-%d') today = datetime.now().strftime('%Y-%m-%d')
@ -378,14 +398,6 @@ class SWIndustryHeatTracker:
# 使用示例 # 使用示例
if __name__ == "__main__": if __name__ == "__main__":
# 数据库配置 # 数据库配置
# config = {
# 'host': 'localhost',
# 'port': 3306,
# 'user': 'your_username',
# 'password': 'your_password',
# 'database': 'your_database',
# 'charset': 'utf8mb4'
# }
config = { config = {
'host': '10.127.2.207', 'host': '10.127.2.207',
'user': 'financial_prod', 'user': 'financial_prod',
@ -401,5 +413,10 @@ if __name__ == "__main__":
db_config=config # 传入数据库配置 db_config=config # 传入数据库配置
) )
check_date = datetime.now().strftime('%Y-%m-%d')
if not tracker.is_trading_day(check_date):
print(f"\n⚠️ {check_date} 不是交易日,跳过计算\n\n")
exit(0)
# 生成报告并自动存入MySQL # 生成报告并自动存入MySQL
result = tracker.generate_report(save=True, to_mysql=True) result = tracker.generate_report(save=True, to_mysql=True)

View File

@ -95,8 +95,8 @@ def update_sw_heat_job():
# --- 3. 启动定时调度器 --- # --- 3. 启动定时调度器 ---
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
# 每天 18:10 执行更新 # 每天 18:25 执行更新
scheduler.add_job(update_sw_heat_job, 'cron', hour=18, minute=10) scheduler.add_job(update_sw_heat_job, 'cron', hour=18, minute=25)
scheduler.start() scheduler.start()
@ -157,7 +157,7 @@ def process_single_message(data):
first_industry = industry_label[0].split("-")[0] first_industry = industry_label[0].split("-")[0]
first_industry_confidence = industry_confidence[0] first_industry_confidence = industry_confidence[0]
if first_industry_confidence >= 0.75: if first_industry_confidence >= 0.75:
sw_heat = sw_heat_map.get(first_industry, 0) sw_heat = sw_heat_map.get(first_industry, 0)
public_opinion_score = tagged_news.get("public_opinion_score", 30) #资讯质量分 public_opinion_score = tagged_news.get("public_opinion_score", 30) #资讯质量分
China_factor = tagged_news.get("China_factor", 0.2) #中国股市相关度 China_factor = tagged_news.get("China_factor", 0.2) #中国股市相关度

View File

@ -24,7 +24,6 @@ def message_callback(ch, method, properties, body):
# 数据写入资讯精选表 # 数据写入资讯精选表
write_to_news(data) write_to_news(data)
# 手动确认消息 # 手动确认消息
ch.basic_ack(delivery_tag=method.delivery_tag) ch.basic_ack(delivery_tag=method.delivery_tag)
except Exception as e: except Exception as e: