Skip to content

Instantly share code, notes, and snippets.

@janewang
Forked from alexclare/gist:3410169
Created August 21, 2012 01:20
Show Gist options
  • Save janewang/3410267 to your computer and use it in GitHub Desktop.
Save janewang/3410267 to your computer and use it in GitHub Desktop.
Hacky IRCCloud ping script
import json, pycurl, subprocess
class ChatStream(object):
def __init__(self, sessid, handler):
self.handler = handler
self.buffer = ''
self.curl = pycurl.Curl()
self.curl.setopt(pycurl.URL, 'https://irccloud.com/chat/stream')
self.curl.setopt(pycurl.COOKIE, 'session=' + sessid)
self.curl.setopt(pycurl.WRITEFUNCTION, self.chunk)
self.curl.perform()
def chunk(self, data):
linebreak = data.find('\n')
if linebreak >= 0:
self.handler(self.buffer + data[:linebreak])
self.buffer = data[linebreak+1:]
else:
self.buffer += data
def handler(msg):
if len(msg) > 0:
decoded = json.loads(msg)
try:
if decoded['highlight'] or decoded['from'] == decoded['chan']:
subprocess.call(['/usr/bin/notify-send',
decoded['from'][:40],
decoded['msg'][:100]])
except KeyError:
pass
# insert your session ID below
ChatStream(sessionID, handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment