钉钉打新债自动提醒-python

1.利用钉钉机器人进行每日打新债自动提醒。

2.在钉钉建立自己的群组,智能群助手中 添加webhook 机器人

3.用以下方式编辑机器人参数,选择加签的形式,

将加签码    替换代码中 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+'&timestamp={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.将该代码放入任务计划程序中,每天打开电脑自动运行,自动提醒自己。下节再介绍怎么放入任务计划程序中。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值