Skip to content

Instantly share code, notes, and snippets.

@katrielalex
Created January 28, 2015 18:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katrielalex/b2d918712fb512fd5e38 to your computer and use it in GitHub Desktop.
Save katrielalex/b2d918712fb512fd5e38 to your computer and use it in GitHub Desktop.
Listen to the Pushbullet websocket stream of events, and hit a key on a particular event.
#!/usr/bin/env python2
import ConfigParser
import time
import json
import os
import requests
import subprocess
import websocket
def toggle_donotdisturb():
script = 'tell application "System Events" to keystroke "D" using {command down, shift down}'
subprocess.check_call(["osascript", "-e", script])
def on_error(ws, error):
print error
def on_close(ws):
print "closed"
def on_message(ws, message):
message = json.loads(message)
if message["type"] == "tickle" and message["subtype"] == "push":
ten_minutes_ago = str(time.time() - 10 * 60 * 1000)
URL = "https://api.pushbullet.com/v2/pushes?modified_after="
data = json.loads(requests.get(URL + ten_minutes_ago, auth=(api_key, '')).content)
if data["pushes"][0]["title"].strip().lower() in ("start pomodoro", "stop pomodoro"):
toggle_donotdisturb()
if __name__ == "__main__":
websocket.enableTrace(True)
parser = ConfigParser.ConfigParser()
parser.read(os.path.expanduser("~/.pushbullet"))
api_key = parser.get("auth", "api-key")
ws = websocket.WebSocketApp("wss://stream.pushbullet.com/websocket/" + api_key,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()
@katrielalex
Copy link
Author

On OSX, you can go to System Preferences -> Keyboard -> Shortcuts -> Mission Control and bind Command-Shift-D to do-not-disturb mode. Then this will toggle do not disturb on specific pushbullets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment