python pushbullet_logging.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python pushbullet_logging.py相关的知识,希望对你有一定的参考价值。

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

import logging
import requests
import json

_session = requests.Session()

#APT KEY
_pushbullet = "XXXXXXXXXXXXXXXXXXXXXXX"

def pushbullet(title,sms):
    headers = {"Content-Type": "application/json"}
    post_data = {"type": "note",
                "title": title,
                "body": sms}
    a = _session.post("https://api.pushbullet.com/v2/pushes",
                        auth =(_pushbullet,""),
                        headers=headers,
                        data=json.dumps(post_data))
    if "error" in a.text:
        raise Exception(u"卧槽,粗大事了")
    return True

class pushbulletHandler(logging.Handler):
    def __init__(self):
        super(pushbulletHandler,self).__init__()
        self.setLevel(logging.CRITICAL)

    def emit(self, record):
        pushbullet(u"某某脚本", self.format(record))

log = logging.getLogger(__name__)
log.addHandler(pushbulletHandler())

log.critical(u"紧急信息,请处理")

以上是关于python pushbullet_logging.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python