代码拉取完成,页面将自动刷新
from bottle import route, request
import wx_request as req
from wx_reply import RepMsg, RepTextMsg
import numpy as np
import bottle
import bottle_mysql
import sys
@route('/stock/forecast', method=['GET'])
def check():
return request.query.echostr
@route('/stock/forecast', method=['POST'])
def handle(db):
data = request.body.read()
req_msg = req.parse_xml(data)
if req_msg is None :
return RepMsg().to_xml()
if req_msg.msg_type != 'text' or req_msg.content is None:
rep_msg = RepTextMsg(req_msg.from_username,req_msg.to_username,"小娜暂时还不能理解您发送的信息,您可以回复\"Help\"获取操作帮助")
return rep_msg.to_xml()
if req_msg.content == "Help" :
help_content = "1、小娜可以帮您预测下一个交易日的买入价和卖出价,您可以回复股票代码获取,比如:要预测'天齐锂业',可以回复'002466';\n"
help_content +="2、数据更新时间为交易日17:30-22:30,数据更新后可以预测下一个交易日价格;\n"
help_content +="3、数据结果由AI通过历史数据预测,不构成投资建议,投资有风险,入市需谨慎"
rep_msg = RepTextMsg(req_msg.from_username,req_msg.to_username,help_content)
return rep_msg.to_xml()
sql = "SELECT * FROM predict_info WHERE code LIKE '%"+req_msg.content+"' ORDER BY date DESC LIMIT 1"
db.execute(sql)
row = db.fetchone()
if row is None:
rep_msg = RepTextMsg(req_msg.from_username,req_msg.to_username,"小娜还没有学习到你查询的股票,目前小娜只支持A股沪深主板上市满30天的股票")
return rep_msg.to_xml()
date = row['date']
code = row['code']
buy_price = np.float64(row['buy_price'])
sell_price = np.float64(row['sell_price'])
#profits = np.float64(row['expected'])
content = "股票:{0}\n次日买价:¥{1:.2f}\n次日卖价:¥{2:.2f}\n声明:此结果根据{3}数据预测,不构成投资建议".format(code,buy_price,sell_price,date)
return RepTextMsg(req_msg.from_username,req_msg.to_username,content).to_xml()
if __name__ == "__main__":
if len(sys.argv) == 2:
plugin = bottle_mysql.Plugin(dbhost='rm-8vby6h31662bd2m29.mysql.zhangbei.rds.aliyuncs.com',dbuser='ghuazo', dbpass='%@Code1314', dbname='stock_forecast')
port = sys.argv[1]
bottle.run(host='172.26.199.181', port=port,plugins=[plugin])
#bottle.run(app,host='127.0.0.1', port=80)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。