38 lines
2.0 KiB
Python
38 lines
2.0 KiB
Python
# from goojia_utils import MysqlClient, ArkAIClient, dingutils
|
|
# from goojia_utils import dateutils
|
|
# from datetime import datetime
|
|
# import requests
|
|
#
|
|
# db_util = MysqlClient(
|
|
# host="192.168.0.93",
|
|
# port=3306,
|
|
# database="stock",
|
|
# user="root",
|
|
# password="Goojia123456"
|
|
# )
|
|
# date = int(dateutils.format_date(dateutils.add_months(datetime.today(), months=-1), fm='%Y%m%d'))
|
|
# select_stocks = db_util.scan_by_sql_to_data_frame("select ts_code as 股票代码, stock_name as 股票名称,close as 股价, pe as PE,turnover_rate as 换手率 from mu_stocks_new where `trade_date`= (select max(`trade_date`) from mu_stocks_new)")
|
|
# stat = db_util.scan_by_sql_to_data_frame(f"select ts_code as 股票代码, count(ts_code) as 命中次数 from mu_stocks_new where `trade_date` > {date} group by ts_code")
|
|
# select_stocks = select_stocks.merge(stat, on='股票代码', how='left')
|
|
# select_stocks['命中次数'] = select_stocks['命中次数'].fillna(0)
|
|
# select_stocks = select_stocks.sort_values(by=['命中次数', 'PE'], ascending=[False, True])
|
|
# def df_to_nested_list(df):
|
|
# """转换为嵌套的 Markdown 列表"""
|
|
# lines = []
|
|
# i= 1
|
|
# for _, row in df.iterrows():
|
|
# lines.append(f"{i}. **{row['股票名称']}** ({row['股票代码']}) PE: {row['PE']} 股价: {row['股价']:.2f} 出现次数: {row['命中次数']} 换手率: {row['换手率']:.2f}")
|
|
# i = i + 1
|
|
# return '\n'.join(lines)
|
|
# data = {
|
|
# "msgtype": "markdown",
|
|
# "markdown": {
|
|
# "title": dateutils.format_date(datetime.today(), fm='%Y%m%d') + "选股策略播报",
|
|
# "text": df_to_nested_list(select_stocks)
|
|
# }
|
|
# }
|
|
# access_token = "1e5f9aaeb90b091bc79652b52800cad2f1dee1ac0990149252511965f6d1c12a"
|
|
# # 发送消息至群
|
|
# msg = requests.post(url='https://oapi.dingtalk.com/robot/send?access_token=' + access_token, json=data).json()
|
|
# msg = requests.post(url='https://oapi.dingtalk.com/robot/send?access_token=45ac47a34dc5491535d77d643512244a85d91d7e74676e9c42446dc06357326e', json=data).json()
|
|
# print(msg) |