Skip to content

Instantly share code, notes, and snippets.

@hivefans
Forked from ficapy/pushbullet_logging.py
Last active March 17, 2020 02:03
Show Gist options
  • Select an option

  • Save hivefans/2b8692f12efb2b6018cd to your computer and use it in GitHub Desktop.

Select an option

Save hivefans/2b8692f12efb2b6018cd to your computer and use it in GitHub Desktop.
|-|{"files":{"pushbullet_logging.py":{"env":"plain"}},"tag":"bigdata"}
#!/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"紧急信息,请处理")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment