将加签码 替换代码中 secret 参数,
将webhook替换代码中 url参数
import time
import hmac
import hashlib
import base64
import urllib.parse
#请更新下面两个参数
secret = '***********************'#请更新自己的加签
url='https://oapi.dingtalk.com/robot/send?access_*************************'#复制自己的
timestamp = str(round(time.time() * 1000))
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
# print(timestamp)
# print(sign)
# 拼接url得到签名
webhook_url=url+'×tamp={timestamp}&sign={sign}'.format(timestamp=timestamp,sign=sign)
#%% 加签后钉钉写法
import requests
import time
import json
request_params = {
"headers": {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
},
"timeout": 10
}
def send_msg(text,webhook_url):
r = requests.post(webhook_url, json={
"msgtype": "text",
"text": {
"content": text
},
"at":{
# "atMobiles":[
# "232132131**" #需要填写自己的手机号,钉钉通过手机号@对应人
# ],
"isAtAll": True #是否@所有人,默认否
}
}, **request_params)
import requests
import time
import json
def get_today_bonds():
r = requests.get("http://data.hexin.cn/ipo/bond/cate/info/",
**request_params)
for bond in r.json():
# print(f"{bond['zqName']}: 申购日期:{bond['sgDate']} 溢价率{bond['disRate']} {bond['today']} {bond['sgDate']}")
#if bond['sgDate']=='2021-11-29':#测试用
if bond['today'] == bond['sgDate']:
text = f"""今日打新: {bond['zqName']} 发行量{bond['issue']}亿 """
send_msg(text,webhook_url)
continue
text= get_today_bonds()
3.将该代码放入任务计划程序中,每天打开电脑自动运行,自动提醒自己。下节再介绍怎么放入任务计划程序中。