Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- WebSocket Client for Growl Notification
- Requirements:
- - websocket-client:
- https://github.com/liris/websocket-client
- - Growl:
- http://growl.info/documentation/developer/python-support.php
- """
- import websocket
- import json
- import Growl
- import urllib2
- class MyGrowl:
- @classmethod
- def get_growl(cls):
- if not hasattr(cls, "g"):
- cls.g = Growl.GrowlNotifier(applicationName="BalibaliNotifier",
- notifications=["Notify"])
- cls.g.register()
- return cls.g
- @classmethod
- def notify(cls, title, description, image_url="", sticky=False):
- g = cls.get_growl()
- g.notify(noteType="Notify",
- title=title,
- description=description,
- icon=cls.get_image(image_url),
- sticky=sticky)
- @staticmethod
- def get_image(url):
- if url:
- return Growl.Image.imageWithData(urllib2.urlopen(url).read())
- def on_message(ws, message):
- MyGrowl.notify(**json.loads(message))
- if __name__ == "__main__":
- # websocket.enableTrace(True)
- ws = websocket.WebSocketApp("ws://localhost:3000/", on_message=on_message)
- ws.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement