Upgrade of python script -- nail group chat robot

Keywords: Python JSON

A small script (for work) The script of monitoring written in this article is the email used when sending monitoring. In fact, it is inconvenient to check the email, so it is upgraded,

In our work, we often use nails. If we can use nails, we can send them directly to our nails after our monitoring is successful. It's simple and convenient

There's a place in nail development documentation, Custom robot

This should be able to meet our office requirements. Let's experiment first, open the nails and choose robot management.

Using a custom robot, click

 

Select group, select generated robot

 

And then create,

In this way, our robot was successfully created. We went to look at the requirements of the document. Unfortunately, the official version of python is not available. Here I use python to boldly debug and test. The code is as follows

 

import  requests,json
url='h#Robot corresponding Webhook addressb'
pagrem={
"msgtype": "text",
    "text": {
        "content": "Server error!"
     },
}
headers={
'Content-Type': 'application/json'
}
f=requests.post(url,data=json.dumps(pagrem),headers=headers)

At this time, I will go to my robot group to see if my robot has finished the work

It's done. It's done. It's functional. There's no problem,

So the next step is to upgrade the script I wrote before.

 

# -*- coding: utf-8 -*-
# @Date    : 2017-09-25 08:50:17
# @Author  : lileilei 
import requests ,json,datetime,time
def send_message(content):
    url = '#Robot corresponding Webhook address'
    pagrem = {
        "msgtype": "text",
        "text": {
            "content": content
        },
        "isAtAll": True
    }
    headers = {
        'Content-Type': 'application/json'
    }
    f = requests.post(url, data=json.dumps(pagrem), headers=headers)
def appindex():
    url='#Monitor url'
    m=requests.get(url)
    if int(m.status_code) !=200:
        send_message(content="app The homepage cannot be loaded normally! Time:%s"%datetime.datetime.now())
        print(u' app shouye is failed')
    else:
        print(u'app The homepage can be accessed normally')
def index():
    url='#Monitor url''
    index=requests.get(url)
    if int(index.status_code) !=200:
        send_message(content="Official website homepage can't be loaded normally! Time:%s"%datetime.datetime.now())
        print(u'guanwangshouye is failed')
    else:
    
        print(u'The homepage of the official website can be accessed normally')
def applogin():
    url='#Monitor url''
    data={
    //parameter
    }
    applogin=requests.post(url,data)
    if int(applogin.status_code) !=200:
        send_message(content="APP Login failed to load normally! Time:%s" % datetime.datetime.now())
        print(u' app login is can not  to login')
    else:
        print(u'app Login can be accessed normally')
if __name__ == '__main__':
    while True:
        try:
            applogin()
            index()
            appindex()
            time.sleep(60)
        except Exception as e:
            print(e)
            continue

Then, go to debug,

After the test, the script can be updated,.

This is how a small python sends the monitoring script of the nail group. In fact, other uses are analogies.

Posted by mosherben on Mon, 04 May 2020 04:44:32 -0700