7 Sprints 全部完成: Sprint 0: 基础设施 (DataManager + MariaDB) Sprint 1: 因子引擎 (34因子/12分类) Sprint 2: VectorBT 回测 (5策略+截面) Sprint 3: Optuna 优化 (+Walk-Forward) Sprint 4: ML 模型 (LightGBM+CatBoost) Sprint 5: Qwen 情绪因子 (三源新闻+日期对齐) Sprint 6: Agent 系统 (4Agent+日报.md/.html) 生产加固 (15项): Tushare双源fallback, SSH自动恢复, pool_pre_ping, save_daily先删后插, load_dotenv绝对路径, 日报5d/20d修复, RiskAgent改上证指数, 昨日对比+数据截止, mac_report utf8mb4, CLAUDE-*.md 9条已知Bug, demo全参数化, djapi数据源归一化, indexDatas API修正 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
'''
|
|
写一个方法:
|
|
1. 接收日期范围
|
|
2. 根据日期范围从表:xwlb_daily 查询数据:news_days, daily_sub_id, news_improve, news_title
|
|
按news_days desc, daily_sub_id asc 排序
|
|
3. 调用mysqlHandle.py 里的查询方法查询数据(仔细阅读video/mysqlHandle)
|
|
'''
|
|
# 调用mysqlHandle中的查询方法
|
|
try:
|
|
from .mysqlHandle import MySQLDB
|
|
except (ImportError, SystemError):
|
|
from mysqlHandle import MySQLDB
|
|
import pandas as pd
|
|
def get_xwlb(start_date, end_date):
|
|
"""
|
|
根据日期范围查询新闻联播数据
|
|
|
|
Args:
|
|
start_date: 开始日期
|
|
end_date: 结束日期
|
|
|
|
Returns:
|
|
查询结果列表
|
|
"""
|
|
# SQL注入警告:使用参数化查询防止SQL注入
|
|
sql = "xwlb_daily"
|
|
columns = "news_days, daily_sub_id, news_improve, news_title"
|
|
where = "news_days >= %s AND news_days <=%s order by news_days desc, daily_sub_id asc"
|
|
params = (start_date, end_date)
|
|
try:
|
|
db = MySQLDB()
|
|
result = db.query_data(sql, columns, where, params)
|
|
print(f"查询到 {len(result)} 条记录")
|
|
finally:
|
|
# 关闭连接
|
|
db.close()
|
|
# 转换为pandas DataFrame
|
|
|
|
df = pd.DataFrame(result)
|
|
|
|
return df
|
|
|
|
|
|
def get_xwlb_fine(start_date, end_date):
|
|
"""
|
|
根据日期范围查询新闻联播数据
|
|
|
|
Args:
|
|
start_date: 开始日期
|
|
end_date: 结束日期
|
|
|
|
Returns:
|
|
查询结果列表
|
|
"""
|
|
# SQL注入警告:使用参数化查询防止SQL注入
|
|
sql = "xwlb_daily_ext"
|
|
columns = "news_date as news_days, sub_id as daily_sub_id, news_content as news_improve, news_title"
|
|
where = "news_date >= %s AND news_date <=%s order by news_date desc, sub_id asc"
|
|
params = (start_date, end_date)
|
|
try:
|
|
db = MySQLDB()
|
|
result = db.query_data(sql, columns, where, params)
|
|
print(f"查询到 {len(result)} 条记录")
|
|
finally:
|
|
# 关闭连接
|
|
db.close()
|
|
# 转换为pandas DataFrame
|
|
|
|
df = pd.DataFrame(result)
|
|
|
|
return df
|
|
|
|
if __name__ == "__main__":
|
|
# 测试代码
|
|
start_date = "2025-01-01"
|
|
end_date = "2025-01-31"
|
|
result = get_xwlb(start_date, end_date)
|
|
print("查询结果:")
|
|
print(result.head())
|
|
print(f"总记录数:{len(result)}") |