python-使用wxpy通过微信发警报error消息

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/liyyzz33/article/details/85088468

参考文档https://wxpy.readthedocs.io/zh/latest/index.html#
环境python3.4-3.6,
pip安装wxpy

pip3.6 install -U wxpy -i “https://pypi.doubanio.com/simple/

#!/usr/bin/python
# -*- coding: utf-8 -*


import urllib
import json
import sys, shutil, os, string, datetime,time

from wxpy import *

...
#定义警报名字和要打开日志文件名
serverip="ip"
name="NAMEl"
timenow=datetime.datetime.now().strftime('%Y%m%d')
logname=name + timenow + ".log"
...


# 初始化机器人,扫码登陆
bot = Bot(console_qr=True, cache_path=True)

#指定接收者
#friend = bot.friends().search(u'NAME')[0]
#print(friend)

#指定接收群,注意要把群在设置里添加到通讯录
group_receiver = ensure_one(bot.groups().search('群名'))

# 指定这个群为接收者
logger = get_wechat_logger(group_receiver)

#要监控的日志
file = open('/data/logs/sys_fatal_error/'+ logname)
file.seek(0, os.SEEK_END)
while 1:
        where = file.tell()
        line = file.readline()
        if not line:
                time.sleep(1)
                file.seek(where)
        else:
                print(line)
                logger.error(line)

#长链接微信登录状态
embed()

猜你喜欢

转载自blog.csdn.net/liyyzz33/article/details/85088468