python3 企业微信机器人发送图片

最近在搞闽政通各种监控,使用paramiko推送脚本取回监控数据入库,写脚本练练脑

刚好企业微信机器人有发送图片功能,简单的试了下,监控并发连接数,搞可视化的图。


想想用机器人斗图一定很happy。。。。。。。。。。。。。。。。。。

image.png



image.png


image.png


附上脚本 生成图片用的是matplotlib模块


import requests
import base64
import hashlib


def wx_image(image):
    
    with open(image, 'rb') as file:                     #转换图片成base64格式
        data = file.read()
        encodestr = base64.b64encode(data)
        image_data = str(encodestr, 'utf-8')
        
    with open(image, 'rb') as file:                   #图片的MD5值
        md = hashlib.md5()
        md.update(file.read())
        image_md5 = md.hexdigest()
        
    url = "https://"                                        #填上机器人Webhook地址 
    headers = {"Content-Type": "application/json"}
    data = {
        "msgtype": "image",
        "image": {
            "base64": image_data,
            "md5": image_md5
        }
    }
    result = requests.post(url, headers=headers, json=data)
    return result
    
if __name__ == '__main__' :
    wx_image(image)


猜你喜欢

转载自blog.51cto.com/junhai/2489175