最近在搞闽政通各类监控,使用paramiko推送脚本取回监控数据入库,写脚本练练脑python
恰好企业微信机器人有发送图片功能,简单的试了下,监控并发链接数,搞可视化的图。json
想一想用机器人斗图必定很happy。。。。。。。。。。。。。。。。。。微信
附上脚本 生成图片用的是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)