Python Small script upgrade-nail swarm chat robot

Source: Internet
Author: User

A Little Foot book (for work)in this article to write the monitoring of the script, send monitoring is the use of the mailbox, in fact, the mailbox check has inconvenient, so upgrade,

We work, often with nails, then if it can be used to nail how good, so that our monitoring success directly sent to our nails, simple and convenient

In the nail development documentation there is a place where custom bots

This should be able to meet our office requirements, first to experiment, open the nail, choose robot Management.

Using a custom robot, click

Select a group and select the generated robot

Then create,

So our robot created successfully, we go to look at the requirements of the document go, unfortunately there is no Python version of the official, I use Python bold to debug to test, the code is as follows

ImportRequests,jsonurl='h#机器人对应的Webhook地址b'Pagrem={"Msgtype":"text",    "text": {        "content":"the server is out of error! "     },}headers={'Content-type':'Application/json'}f=requests.post (Url,data=json.dumps (Pagrem), headers=headers)

This time I went to my group to create the robot to see if my robot had finished the work.

Complete, complete, function is properly done, no problem,

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

#-*-coding:utf-8-*-#@Date: 2017-09-25 08:50:17#@Author: LileileiImportrequests, Json,datetime,timedefsend_message (content): URL='#机器人对应的Webhook地址'Pagrem= {        "Msgtype":"text",        "text": {            "content": Content},"Isatall": True} headers= {        'Content-type':'Application/json'} f= Requests.post (URL, data=json.dumps (pagrem), headers=headers)defappindex (): URL='#监控url'm=requests.get (URL)ifInt (m.status_code)!=200: send_message (Content="App homepage does not load properly! Time is:%s"%Datetime.datetime.now ())Print(U'app Shouye is failed')    Else:        Print(U'The App homepage can be accessed normally')defindex (): URL='#监控url"'index=requests.get (URL)ifInt (index.status_code)!=200: send_message (Content="official homepage can't load properly! Time is:%s"%Datetime.datetime.now ())Print(U'Guanwangshouye is failed')    Else:            Print(U'Official homepage can be accessed normally')defapplogin (): URL='#监控url"'Data={parameter} applogin=requests.post (url,data)ifInt (applogin.status_code)!=200: send_message (Content="app login does not load properly! Time is:%s"%Datetime.datetime.now ())Print(U'App Login is a can not to login')    Else:        Print(U'App login can be accessed normally')if __name__=='__main__':     whileTrue:Try: Applogin () index () Appindex () Time.sleep (60)        exceptException as E:Print(e)Continue

Then, go and Debug.

After the test is complete, the script can be updated.

This is how a small Python-sent pin group's monitoring script is completed. In fact, other usages are analogies.

Python Small script upgrade-nail swarm chat robot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.