Skip to content

Instantly share code, notes, and snippets.

@ficapy
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ficapy/f3d280874106acb65276 to your computer and use it in GitHub Desktop.
Save ficapy/f3d280874106acb65276 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding:utf-8
import logging
import requests
import json
_session = requests.Session()
# APT KEY
_pushbullet = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
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)
# 懒得写 直接复制的format T_T
FORMAT = '%(asctime)-15s %(levelname)-6s %(message)s'
DATE_FORMAT = '%b %d %H:%M:%S'
formatter = logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)
self.setFormatter(formatter)
def emit(self, record):
pushbullet(u"某某脚本", self.format(record))
if __name__ == '__main__':
log = logging.getLogger(__name__)
log.addHandler(PushbulletHandler())
try:
1 / 0
except:
log.critical(u"紧急信息,请处理", exc_info=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment