增加一个判断是否为交易日的机制
This commit is contained in:
parent
d67e85ac87
commit
527e31f0f5
|
|
@ -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)
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue