Created
February 3, 2015 05:38
-
-
Save efrenfuentes/5344d9984eb58f48cc26 to your computer and use it in GitHub Desktop.
Get Pushbullet notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import websocket | |
import json | |
import logging | |
import datetime | |
api_key = 'Put your API Key here' | |
url = 'wss://stream.pushbullet.com/websocket/' + api_key | |
logging.basicConfig(filename='pushbullet.log', level=logging.INFO, | |
format='%(asctime)s:%(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') | |
def on_message(ws, message): | |
push_data = json.loads(message, strict=False) | |
if push_data['type'] != 'nop': | |
logging.info(message) | |
if push_data['type'] == 'push': | |
if push_data['push']['type'] == 'mirror': | |
notification = "{0}|{1}|{2}|{3}".format(datetime.datetime.now().isoformat(), | |
push_data['push']['application_name'], | |
push_data['push']['title'], | |
push_data['push']['body']) | |
with open("notifications.dat", "a") as notifications_file: | |
notifications_file.write(notification) | |
def on_error(ws, error): | |
logging.error(error) | |
def on_open(ws): | |
logging.info("### opened ###") | |
def on_close(ws): | |
logging.info("### closed ###") | |
if __name__ == "__main__": | |
ws = websocket.WebSocketApp(url, | |
on_open=on_open, | |
on_message=on_message, | |
on_error=on_error, | |
on_close=on_close) | |
ws.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment