Created
August 28, 2013 16:32
-
-
Save marsam/6368079 to your computer and use it in GitHub Desktop.
campfire notifier
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from gevent import monkey; monkey.patch_all() # noqa | |
| import re | |
| import signal | |
| import logging | |
| import gevent | |
| from campfire import Campfire | |
| from gi.repository import Notify | |
| logging.basicConfig(level=logging.DEBUG) | |
| MENTIONS = re.compile('(?:marsam|mario|all|everybody|help)', flags=re.IGNORECASE | re.UNICODE) | |
| class CampfireNotifier(object): | |
| name = 'Campfire notifier' | |
| def __init__(self, campfire, rooms): | |
| self.rooms = rooms | |
| self.campfire = campfire | |
| Notify.init(self.name) | |
| def listen_mentions(self, room): | |
| logging.info('subscribing to room: %s', room) | |
| for msg in self.campfire.stream(room): | |
| logging.info('Received msg: %s', msg) | |
| msg_body = msg['body'] | |
| #if msg_body and re.match(MENTIONS, msg_body): | |
| if msg_body: | |
| Notify.Notification.new(self.name, msg_body, 'dialog-information').show() | |
| gevent.sleep(0) | |
| def run(self): | |
| gevent.signal(signal.SIGQUIT, gevent.shutdown) | |
| gevent.joinall([gevent.spawn(self.listen_mentions, room) for room in self.rooms]) | |
| if __name__ == '__main__': | |
| campfire = Campfire('lucuma', '') | |
| notifier = CampfireNotifier(campfire, rooms=['432183', '530745', '433622']) | |
| notifier.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment