Created
June 5, 2016 17:12
-
-
Save aniline/71799c312a3b65ed9d8e94fbccc41078 to your computer and use it in GitHub Desktop.
CLIP desktop notification
This file contains 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
#!/usr/bin/env python | |
import sys, json | |
from gi.repository import Notify | |
sys.path.append("paho-mqtt-1.2/src/") | |
import paho.mqtt.client as mqtt | |
def _on_connect(client, userdata, rc): | |
print "Connected." | |
(rc, mid) = client.subscribe("/clip/cooked") | |
print "Subcribe rc = " + str(rc) + " mid = " + str(mid) | |
def _on_message(client, userdata, msg): | |
print "Message: " + msg.payload | |
try: | |
pl = json.loads(msg.payload) | |
if pl.has_key('num'): | |
userdata.props.body = '<b>'+pl['disp']+'</b> ('+pl['num']+')' | |
else: | |
userdata.props.body = '<b>Error, no number found</b>' | |
except ValueError, e: | |
userdata.props.body = '<b>Error, Bad message</b>' | |
userdata.show() | |
def _on_subscribe(client, userdata, mid, g_qos): | |
print "Subscribed." | |
def _on_disconnect(client, userdata, rc): | |
print "Disconnected." | |
Notify.init("CLIP_Notification") | |
clip_notify = Notify.Notification.new("Incoming Call", "Starting Clip", "dialog-information") | |
client = mqtt.Client(userdata=clip_notify) | |
client.on_connect = _on_connect | |
client.on_message = _on_message | |
client.on_subscribe = _on_subscribe | |
client.on_disconnect = _on_disconnect | |
client.connect("192.168.1.22", 1883, 60) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment