예제 #1
0
    def timeline(self, timeline=None, since_id=None, count=DEFAULT_FETCH,
            callback=None, loadImages=True):
        args = {'count' : count}
        search = False
        if timeline.startswith('search.json'):
            # Special case search timeline
            search = True
            args = {'rpp' : count}

        if since_id:
            args['since_id'] = since_id

        sep = '?'
        if timeline.find('?') >= 0:
            sep = '&'
        data = None
        try:
            util.get_global('app').in_progress = True
            data = self._fetch('/%s%s%s' % (timeline, sep, urllib.urlencode(args)))
            if loadImages:
                if search:
                    data = data['results']
                for status in data:
                    who, img = None, None
                    if not search:
                        who = status['user']['screen_name']
                        img = status['user']['profile_image_url']
                    else:
                        who = status['from_user']
                        img = status['profile_image_url']

                    try:
                        util.saveImageToFile(who, img)
                    except Exception, ex:
                        logging.error('Downloading failed: %s %s' % (status, ex))
        finally:
            util.get_global('app').in_progress = False
            if not callback:
                return data
            gobject.idle_add(callback, data)
예제 #2
0
    def _timerUpdatedCallback(self, data, **kwargs):
        signals.emit(signals.PROGRESS_STOP)
        if not self.rendered:
            self.renderTo(self.parent)
            self.rendered = True

        odd = True
        try:
            if data:
                logging.debug('_timerUpdatedCallback [%s], # items: %s' % (self.timeline, len(data)))

                notify.notify('%s updated' % self.name,
                        '%d new tweets :)' % len(data), None)
                self.since_id = data[0]['id']
                data.reverse()

                for i, status in enumerate(data):
                    what = status['text']
                    
                    # *Very* crude dupe checking
                    if i > 0:
                        prev = data[i-1]
                        if prev['text'] == what:
                            continue

                    renderer = None
                    for view in util.get_global('views'):
                        if not view.matchForText(status):
                            continue
                        renderer = view
                        break

                    logging.debug('rendering %s with %s' % (status['id'], renderer))

                    if not renderer:
                        continue

                    row = renderer.rowForText(status) 
                    self.users.add(row.who)
                    self.rows.insert(0, row)
                    row.renderTo(self.timeline_widget)
        finally:
            gobject.timeout_add_seconds(INTERVAL, self._timerCallback)