当前位置:网站首页>Teach you to build a nail warning robot hand in hand
Teach you to build a nail warning robot hand in hand
2022-07-27 08:03:00 【Shenzhi Kalan Temple】
Abstract
With the continuous increase of production and on-line business and the increasing demand for unattended , The emergence of nail warning robot has greatly solved our problem . This paper starts from 0 To 1 Introduce and explain in detail the construction and customization of the nail early warning robot , It is divided into robot construction , Early warning content development , Three steps for online deployment
Robot building
All the following configuration development comes from Nail official website documents , If you like to read the official website or have further personalized needs, you can go to check , You can also build it step by step from the perspective of junior developers with the essayist
The first is to have a group and you have the permission to add robots to this group , then
- Add robots
Group settings -- Intelligent group assistant -- Add robots -- Customize , Select Add , Then make the relevant settings

- Set up the robot

Start with a nice name , There are three security settings , There must be at least one
- Custom keywords : Customize the keywords of sending content , The content sent will only be sent if it contains the set keywords
- The signature of the : That is encryption , Generally, this one is used more ,
- IP Address : It's easy to understand , specific IP You can send content
Here we choose the second countersign , Then click Add , Here the group will prompt you that you have successfully added a robot
We open the robot and save the two data , Namely Webhook token And the countersigned ciphertext
https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxWebhook: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxx
The signature of the :yyyyyyyyyyyyyyyyyyy
these two items. xxxxxx and yyyyy Keep it in reserve
Early warning content development
The above robots are added , Equivalent to a receiving data API The interface is ready , We are now developing early warning content
Use the simplest python, The overall framework code is as follows
from datetime import datetime, timedelta
import requests
import hmac
import hashlib
import base64
import urllib.parse
import urllib.request
import json
import time
import os
import sys
import re
def getUrl(secret,access_token):
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))
url = "https://oapi.dingtalk.com/robot/send?access_token=%s&sign=%s×tamp=%s" % (access_token, sign, timestamp)
return url
def sendToGroup(url,header,data):
sendData = json.dumps(data)# Convert dictionary type data to json Format
sendData = sendData.encode("utf-8") # python3 Of Request requirement data by byte type
request = urllib.request.Request(url=url, data=sendData, headers=header)
opener = urllib.request.urlopen(request)
return opener
secret= ''
access_token=''
data={
"msgtype": "text",
"text": {
"content": " The analysis task has been completed "
},
"at": {
"atMobiles": ["13216816870"],
"isAtAll": False
}
}
header = {
"Content-Type": "application/json",
"Charset": "UTF-8"
}
url=getUrl(secret,access_token)
opener=sendToGroup(url,header,data)Put the above xxxx and yyyy Put it in the code secret and access_token, Can run , The nail robot will pop up

What the whole content needs to be developed is in the code data Which part
Our common query is through the database , So we also connect to the database to query , Add one more sql function code
def exeSqlRes(dbip,dbport,dbacco,dbpwd,dbname,sql):
conn = connect(host=dbip, port=dbport, user=dbacco, password=dbpwd, database=dbname)
cursor = conn.cursor()
try:
cursor.execute(sql)
list1 = cursor.fetchall()
global dataStr1,dataStr2
dataStr1 = " In line operation date :%s" % (list1[0][0])
dataStr2 = " Public offering operation date :%s" % (list1[1][0])
except:
print(" Database connection failed \n")
conn.close()
sql = '''
SELECT SZ_TO_CHAR_D(max(d_date),'YYYYMMDD') as SYSTEMDATE from datacollect_log
union all
SELECT SZ_TO_CHAR_D(max(d_date),'YYYYMMDD') as SYSTEMDATE from datacollect_log
)
'''
exeSqlRes('xx.xx.xx.xx',3306,'xxxxx','xxxxx','xxxxx',sql)data The official website of nailing introduces a lot , Yes txt,json,xml etc. , Limited to space , Here we only list the most commonly used MARKDOWN form
data = {
"msgtype": "markdown",
"markdown": {
"title":" Data monitoring ",
"text": "#### Current data run date @17665011132 \n > - **%s** \n > - **%s** \n > \n > ###### %s Release [ Check the details ](https://www.dingtalk.com) \n" % (dataStr1,dataStr2,timeStr)
},
"at": {
"atMobiles": [
"176xxxx1132"
],
"atUserIds": [
""
],
"isAtAll": "false"
}
}You can do it according to your actual needs data Development , After I finish the development here, the code pops up

All configurations are completed
Online deployment
Put this python Put the code in crontab It can be scheduled to run on demand
*/10 * * * * /bisz/python/anaconda3/bin/python /bisz/python/DingDingSend.py
边栏推荐
- 【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
- Debug: generic related "unresolved external symbols"
- 鲁迅:我不记得说没说过,要不你自己查!
- 物来顺应,未来不迎,当时不杂,既过不恋
- Digital transformation driven by enterprise architecture!
- [applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
- PHP realizes data interaction with MySQL
- 数据库启动报error_user_connect_times > 0错误
- C语言:随机生成数+希尔排序
- 瑞芯微RK3399-I2C4挂载EEPROM的修改案例
猜你喜欢

Framework of electronic mass production project -- basic idea

Day111. Shangyitong: integrate nuxt framework, front page data, hospital details page

Translation character '/b' in C #

Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money

Do me a favor ~ don't pay attention, don't log in, a questionnaire in less than a minute

【飞控开发基础教程4】疯壳·开源编队无人机-串口(光流数据获取)

Lu Xun: I don't remember saying it, or you can check it yourself!

自动化测试的使用场景

Promise details

How to log in multiple wechat on the computer
随机推荐
如何在 60 秒内去分析和定位问题?
MCU multi-level menu
一段平平无奇的秋招经历
数据提取1
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
An ordinary autumn recruitment experience
Harbor正确密码登录不上去
Interview reply V
【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件
大家节日快乐哈
PHP realizes data interaction with MySQL
Chromedriver download - self use
数据提取2
API version control [eolink translation]
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
How to play with the purchase of SAP variant materials? Look at this article and you will understand
CommonTitleBar hide left right
Day111. Shangyitong: integrate nuxt framework, front page data, hospital details page
【目标检测】YOLOv6理论解读+实践测试VisDrone数据集
Dasctf2022.07 enabling game password WP