最近在搞閩政通各類監控,使用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)