Exemple #1
0
 def listsongs(self, event, username):
     songs = feedparser.parse('http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss?%s' % (username, time()))
     if songs['bozo']:
         event.addresponse(u'No such user')
     else:
         event.addresponse(u', '.join(u'%s (%s ago)' % (
                 e.title,
                 ago(event.time - parse_timestamp(e.updated))
             ) for e in songs['entries']))
Exemple #2
0
 def listsongs(self, event, username):
     songs = feedparser.parse(
         'http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss?%s' %
         (username, time()))
     if songs['bozo']:
         event.addresponse(u'No such user')
     else:
         event.addresponse(u', '.join(
             u'%s (%s ago)' %
             (e.title, ago(event.time - parse_timestamp(e.updated)))
             for e in songs['entries']))
Exemple #3
0
    def remote_latest(self, service, user):
        if service['api'] == 'twitter':
            # Twitter ommits retweets in the JSON and XML results:
            statuses = generic_webservice(
                '%sstatuses/user_timeline/%s.atom' %
                (service['endpoint'], user.encode('utf-8')), {'count': 1})
            tree = ElementTree.fromstring(statuses)
            latest = tree.find('{http://www.w3.org/2005/Atom}entry')
            if latest is None:
                raise self.NoTweetsException(user)
            return {
                'text':
                latest.findtext('{http://www.w3.org/2005/Atom}content').split(
                    ': ', 1)[1],
                'ago':
                ago(datetime.utcnow() - parse_timestamp(
                    latest.findtext('{http://www.w3.org/2005/Atom}published'))
                    ),
                'url': [
                    x for x in latest.getiterator(
                        '{http://www.w3.org/2005/Atom}link')
                    if x.get('type') == 'text/html'
                ][0].get('href'),
            }
        elif service['api'] == 'laconica':
            statuses = json_webservice(
                '%sstatuses/user_timeline/%s.json' %
                (service['endpoint'], user.encode('utf-8')), {'count': 1})
            if not statuses:
                raise self.NoTweetsException(user)
            latest = statuses[0]
            url = '%s/notice/%i' % (service['endpoint'].split(
                '/api/', 1)[0], latest['id'])

        return {
            'text': decode_htmlentities(latest['text']),
            'ago':
            ago(datetime.utcnow() - parse_timestamp(latest['created_at'])),
            'url': url,
        }
Exemple #4
0
    def remote_latest(self, service, user):
        if service['api'] == 'twitter':
            # Twitter ommits retweets in the JSON and XML results:
            statuses = generic_webservice(
                '%sstatuses/user_timeline.rss' % service['endpoint'], {
                    'screen_name': user,
                    'count': 1
                })
            tree = ElementTree.fromstring(statuses)
            latest = tree.find('.//item')
            if latest is None:
                if tree.find('.//error'):
                    log.info('Twitter user_latest returned: %s',
                             tree.findtext('.//error'))
                raise self.NoTweetsException(user)
            return {
                'text':
                latest.findtext('description').split(': ', 1)[1],
                'ago':
                ago(datetime.utcnow() -
                    parse_timestamp(latest.findtext('pubDate'))),
                'url':
                latest.findtext('guid'),
            }
        elif service['api'] == 'laconica':
            statuses = json_webservice(
                '%sstatuses/user_timeline/%s.json' %
                (service['endpoint'], user.encode('utf-8')), {'count': 1})
            if not statuses:
                raise self.NoTweetsException(user)
            latest = statuses[0]
            url = '%s/notice/%i' % (service['endpoint'].split(
                '/api/', 1)[0], latest['id'])

        return {
            'text': decode_htmlentities(latest['text']),
            'ago':
            ago(datetime.utcnow() - parse_timestamp(latest['created_at'])),
            'url': url,
        }
Exemple #5
0
    def remote_latest(self, service, user):
        if service['api'] == 'twitter':
            # Twitter ommits retweets in the JSON and XML results:
            statuses = generic_webservice('%sstatuses/user_timeline.rss'
                                          % service['endpoint'], {
                                              'screen_name': user,
                                              'count': 1
                                          })
            tree = ElementTree.fromstring(statuses)
            latest = tree.find('.//item')
            if latest is None:
                if tree.find('.//error'):
                    log.info('Twitter user_latest returned: %s',
                             tree.findtext('.//error'))
                raise self.NoTweetsException(user)
            return {
                'text': latest.findtext('description')
                        .split(': ', 1)[1],
                'ago': ago(datetime.utcnow() - parse_timestamp(
                    latest.findtext('pubDate'))),
                'url': latest.findtext('guid'),
            }
        elif service['api'] == 'laconica':
            statuses = json_webservice('%sstatuses/user_timeline/%s.json'
                    % (service['endpoint'], user.encode('utf-8')),
                    {'count': 1})
            if not statuses:
                raise self.NoTweetsException(user)
            latest = statuses[0]
            url = '%s/notice/%i' % (service['endpoint'].split('/api/', 1)[0],
                                    latest['id'])

        return {
            'text': decode_htmlentities(latest['text']),
            'ago': ago(datetime.utcnow()
                       - parse_timestamp(latest['created_at'])),
            'url': url,
        }
Exemple #6
0
    def remote_latest(self, service, user):
        if service['api'] == 'twitter':
            # Twitter ommits retweets in the JSON and XML results:
            statuses = generic_webservice('%sstatuses/user_timeline/%s.atom'
                    % (service['endpoint'], user.encode('utf-8')),
                    {'count': 1})
            tree = ElementTree.fromstring(statuses)
            latest = tree.find('{http://www.w3.org/2005/Atom}entry')
            if latest is None:
                raise self.NoTweetsException(user)
            return {
                'text': latest.findtext('{http://www.w3.org/2005/Atom}content')
                        .split(': ', 1)[1],
                'ago': ago(datetime.utcnow() - parse_timestamp(
                    latest.findtext('{http://www.w3.org/2005/Atom}published'))),
                'url': [x for x
                     in latest.getiterator('{http://www.w3.org/2005/Atom}link')
                     if x.get('type') == 'text/html'
                  ][0].get('href'),
            }
        elif service['api'] == 'laconica':
            statuses = json_webservice('%sstatuses/user_timeline/%s.json'
                    % (service['endpoint'], user.encode('utf-8')),
                    {'count': 1})
            if not statuses:
                raise self.NoTweetsException(user)
            latest = statuses[0]
            url = '%s/notice/%i' % (service['endpoint'].split('/api/', 1)[0],
                                    latest['id'])

        return {
            'text': decode_htmlentities(latest['text']),
            'ago': ago(datetime.utcnow()
                       - parse_timestamp(latest['created_at'])),
            'url': url,
        }