Пример #1
0
    def run(self):
        # XXX: Wait for the command line to initialize
        time.sleep(1.0)

        with closing(self._connection):
            headers = {}
            while True:
                try:
                    url = config['LIVE_URL']
                    event = self._connection.request('GET', url, headers)
                except NetworkError, e:
                    n = 10
                    error('{msg}, waiting for {n} secs...'.format(
                              msg=unicode(e),
                              n=n))
                    time.sleep(n)
                    continue

                messages = event.get('messages', [])
                if messages:
                    headers['cursor'] = messages[-1].get('_id', 'null')
                for f in self._callbacks:
                    try:
                        for m in messages:
                            f(m)
                    except Exception, e:
                        error(unicode(e), exc=e)
Пример #2
0
    def run(self):
        # XXX: Wait for the command line to initialize
        time.sleep(1.0)

        url = '/api/live.json'
        headers = {}
        timeout = 10

        with closing(self._connection):
            while True:
                try:
                    event = self._connection.request('GET', url, headers)
                except NetworkError, e:
                    error('{msg}, waiting for {n} secs...'.format(
                        msg=unicode(e), n=timeout))
                    time.sleep(timeout)
                    continue

                messages = event.get('messages', [])
                if messages:
                    headers['cursor'] = messages[-1].get('_id', 'null')
                for f in self._callbacks:
                    try:
                        for m in messages:
                            f(m)
                    except Exception, e:
                        error(unicode(e), exc=e)
Пример #3
0
def main():
    try:
        opts, args = getopt(sys.argv[1:], b'h',
                            [b'help', b'debug', b'no-notify'])
    except GetoptError, e:
        error(bytes(e).decode(ENCODING, errors='replace'))
        usage()
        sys.exit(1)
Пример #4
0
def main():
    try:
        opts, args = getopt(sys.argv[1:],
                            b'h',
                            [b'help', b'debug', b'no-notify'])
    except GetoptError, e:
        error(bytes(e).decode(ENCODING, errors='replace'))
        usage()
        sys.exit(1)
Пример #5
0
    def cmd_ts(self, group_slug=None):
        def latest_message(x):
            return x.get('date_latest_message')

        try:
            all_topics = list(self.convore.get_topics().values())
            groups = list(self.convore.get_groups().values())
        except NetworkError, e:
            error(unicode(e))
            return
Пример #6
0
 def __init__(self, convore):
     self.convore = convore
     self.convore.on_live_update(self.handle_live_update)
     if os.path.exists(config['NOTIFY_SEND']):
         self.enabled = True
     else:
         error('desktop notifications are disabled: '
               '"{0}" not found'.format(config['NOTIFY_SEND']))
         self.enabled = False
     self._tmpdir = mkdtemp()
Пример #7
0
 def Image(self):
     if not hasattr(self, '_Image'):
         try:
             from PIL import Image
             self._Image = Image
         except ImportError:
             error('Python Imaging Library is not installed, '
                   'no avatars will be shown')
             self._Image = None
     return self._Image
Пример #8
0
 def loop(self):
     output('welcome to convoread! type /help for more info')
     while True:
         try:
             data = raw_input(config['PROMPT'])
             self.dispatch(data.decode(config['ENCODING'], 'replace'))
         except EOFError:
             raise
         except Exception, e:
             error(unicode(e), exc=e)
Пример #9
0
 def __init__(self, convore):
     self.convore = convore
     self.convore.on_live_update(self.handle_live_update)
     if os.path.exists(config['NOTIFY_SEND']):
         self.enabled = True
     else:
         error('desktop notifications are disabled: '
               '"{0}" not found'.format(config['NOTIFY_SEND']))
         self.enabled = False
     self._tmpdir = mkdtemp()
Пример #10
0
 def loop(self):
     output('welcome to convoread! type /help for more info')
     while True:
         try:
             data = raw_input(config['PROMPT'])
             self.dispatch(data.decode(config['ENCODING'], 'replace'))
         except EOFError:
             raise
         except Exception, e:
             error(unicode(e), exc=e)
Пример #11
0
 def Image(self):
     if not hasattr(self, '_Image'):
         try:
             from PIL import Image
             self._Image = Image
         except ImportError:
             error('Python Imaging Library is not installed, '
                   'no avatars will be shown')
             self._Image = None
     return self._Image
Пример #12
0
    def cmd_ts(self, group_slug=None):
        def latest_message(x):
            return x.get('date_latest_message')

        try:
            all_topics = list(self.convore.get_topics().values())
            groups = list(self.convore.get_groups().values())
        except NetworkError, e:
            error(unicode(e))
            return
Пример #13
0
 def sendmsg(self, msg):
     if not self.topic:
         error('no topic set, type /help for more info')
         return
     msg = msg.strip()
     if not msg:
         return
     debug('sending "{0}"...'.format(msg))
     try:
         self.convore.send_message(self.topic, msg)
     except NetworkError, e:
         error(unicode(e))
Пример #14
0
 def sendmsg(self, msg):
     if not self.topic:
         error('no topic set, type /help for more info')
         return
     msg = msg.strip()
     if not msg:
         return
     debug('sending "{0}"...'.format(msg))
     try:
         self.convore.send_message(self.topic, msg)
     except NetworkError, e:
         error(unicode(e))
Пример #15
0
 def cmd_m(self, group_slug=None):
     try:
         if group_slug:
             groups = [g for g in self.convore.get_groups().values()
                         if g.get('slug') == group_slug]
             if not groups:
                 error('group "{0}" not found'.format(group_slug))
                 return
             group = groups[0]
             self.convore.mark_group_read(group.get('id'))
         else:
             self.convore.mark_all_read()
     except NetworkError, e:
         error(unicode(e))
Пример #16
0
 def cmd_t(self, topic_id=None):
     count = 10
     if topic_id:
         self.topic = topic_id
     else:
         if self.topic:
             topic_id = self.topic
         else:
             error('no topic set, type /help for more info')
             return
     try:
         messages = self.convore.get_topic_messages(topic_id)
     except NetworkError, e:
         error(unicode(e))
         return
Пример #17
0
 def cmd_t(self, topic_id=None):
     count = 10
     if topic_id:
         self.topic = topic_id
     else:
         if self.topic:
             topic_id = self.topic
         else:
             error('no topic set, type /help for more info')
             return
     try:
         messages = self.convore.get_topic_messages(topic_id)
     except NetworkError, e:
         error(unicode(e))
         return
Пример #18
0
 def cmd_m(self, group_slug=None):
     try:
         if group_slug:
             groups = [
                 g for g in self.convore.get_groups().values()
                 if g.get('slug') == group_slug
             ]
             if not groups:
                 error('group "{0}" not found'.format(group_slug))
                 return
             group = groups[0]
             self.convore.mark_group_read(group.get('id'))
         else:
             self.convore.mark_all_read()
     except NetworkError, e:
         error(unicode(e))
Пример #19
0
 def cmd_t(self, topic_id=None):
     count = 10
     if topic_id:
         try:
             topic_id = int(topic_id)
         except ValueError:
             error('bad topic number: "{0}"'.format(topic_id))
             return
         self.topic = topic_id
     else:
         if self.topic:
             topic_id = self.topic
         else:
             error('no topic set, type /help for more info')
             return
     try:
         messages = self.convore.get_topic_messages(topic_id)
     except NetworkError, e:
         error(unicode(e))
         return
Пример #20
0
 def dispatch(self, msg):
     badcmd = 'bad command, type /help for more info'
     if not msg:
         return
     if msg.startswith('/'):
         args = msg[1:].split()
         try:
             cmd = args.pop(0)
         except IndexError:
             error(badcmd)
             return
         method = getattr(self, 'cmd_' + cmd, None)
         if method:
             try:
                 method(*args)
             except TypeError:
                 error(badcmd)
                 return
         else:
             error(badcmd)
     else:
         self.sendmsg(msg)
Пример #21
0
 def dispatch(self, msg):
     badcmd = 'bad command, type /help for more info'
     if not msg:
         return
     if msg.startswith('/'):
         args = msg[1:].split()
         try:
             cmd = args.pop(0)
         except IndexError:
             error(badcmd)
             return
         method = getattr(self, 'cmd_' + cmd, None)
         if method:
             try:
                 method(*args)
             except TypeError:
                 error(badcmd)
                 return
         else:
             error(badcmd)
     else:
         self.sendmsg(msg)
Пример #22
0
    def cmd_ts(self, group_slug=None):
        def latest_message(x):
            return x.get('date_latest_message')

        try:
            all_topics = list(self.convore.get_topics().values())
            groups = list(self.convore.get_groups().values())
        except NetworkError, e:
            error(unicode(e))
            return

        if group_slug:
            groups = [g for g in groups if g.get('slug') == group_slug]
            if not groups:
                error('group "{0}" not found'.format(group_slug))
                return

        groups = sorted(groups, key=latest_message, reverse=True)

        for group in groups:
            output('{name}:'.format(name=group.get('slug', '(unknown)')))
            topics = [
                t for t in all_topics if t.get('group') == group.get('id')
            ]
            topics = sorted(topics, key=latest_message, reverse=True)
            for topic in topics:
                unread = topic.get('unread', 0)
                if not group_slug and unread == 0:
                    continue
                msg = '  {mark} {id:6} {new:2} {name}'.format(
Пример #23
0
        def latest_message(x):
            return x.get('date_latest_message')

        try:
            all_topics = list(self.convore.get_topics().values())
            groups = list(self.convore.get_groups().values())
        except NetworkError, e:
            error(unicode(e))
            return

        if group_slug:
            groups = [g for g in groups
                        if g.get('slug') == group_slug]
            if not groups:
                error('group "{0}" not found'.format(group_slug))
                return

        groups = sorted(groups, key=latest_message, reverse=True)

        for group in groups:
            output('{name}:'.format(
                name=group.get('slug', '(unknown)')))
            topics = [t for t in all_topics if t.get('group') == _id(group)]
            topics = sorted(topics, key=latest_message, reverse=True)
            for topic in topics:
                unread = topic.get('unread', 0)
                if not group_slug and unread == 0:
                    continue
                msg = '  {mark} {id:6} {new:2} {name}'.format(
                    mark='*' if _id(topic) == self.topic else ' ',