作为一个程序员天天钉盘,真是浪费时间。留点时间学习进度很有必要。毕竟疫情期间,各种紧张工作还有基市也是如此。
自己写一个报警器 就很有必要了。
写一个简单的案例为以后高级进阶铺路。
使用钉钉报警(毕竟穷,有白嫖不能错过,如何申请自行百度so easy)
大体策略是从天天基金里抓取相关数据 每周一 09:30发送报表
实现效果如图
软件效果图.png
import requests
import re
import lxml
from bs4 import BeautifulSoup
import json
import datetime
import schedule
p_json = re.compile(r'(\[.*\])')
#url = 'http://fundsc.eastmoney.com/2017/paihanglei/4433/pc/'
url = 'http://fundsc.eastmoney.com/2017/paihanglei/4433/funds.js'
def SendDD(ddcontent):
# 请求地址
post_url = "https://oapi.dingtalk.com/robot/send?access_token=钉钉的token"
# 消息头部
headers = {'Content-Type': 'application/json'}
# 消息主体
data = {
"msgtype": "text",
"text": {
"content": ddcontent
}
}
# 使用post请求推送消息
requests.post(post_url, data=json.dumps(data), headers=headers)
def FindJJ():
today = datetime.datetime.today()
print(today)
if today.strftime("%w") != "1":
return
print("start FindJJ")
response = requests.request("get",url)
response.encoding = "utf-8"
#print(response.content)
content = str(response.content,encoding="utf-8")
content = content[content.index("["):content.index("]")+1]
jjs = json.loads(content)
#给收益排序
sendtxt = "近三年收益报表,根据4433策略选基\n"
jjs.sort(key=lambda x:float(x["SYL"]), reverse=True)
for js in jjs:
#print(js["FCODE"],js["SHORTNAME"],js["FTYPE"],js["PERIODNAME"],js["SYL"])
sendtxt += " ".join([js["FCODE"],js["SHORTNAME"],js["FTYPE"],js["SYL"]+"%","\n"])
#通知钉钉基金关注基金 每周1 通知一次
SendDD(sendtxt)
#print(sendtxt)
FindJJ()
schedule.every().day.at('09:30').do(FindJJ)
#schedule.every().day.at('18:02').do(FindJJ)
print("开始定时抓取数据")
while True:
schedule.run_pending()