Example #1
0
    def __init__(self):
        Protocol.__init__(self, 'Twitter', 'http://api.twitter.com/1',
                          'http://search.twitter.com',
                          'http://twitter.com/search?q=%23', None,
                          'http://www.twitter.com')

        self.http = TwitterHTTP(self.apiurl)
        self.retweet_by_me = []
        self.oauth_support = False
Example #2
0
 def __init__(self):
     Protocol.__init__(self, 'Twitter', 'http://api.twitter.com/1', 
         'http://search.twitter.com', 'http://twitter.com/search?q=%23',
         None, 'http://www.twitter.com')
     
     self.http = TwitterHTTP(self.apiurl)
     self.retweet_by_me = []
     self.oauth_support = False
Example #3
0
class Twitter(Protocol):
    def __init__(self):
        Protocol.__init__(self, 'Twitter', 'http://api.twitter.com/1', 
            'http://search.twitter.com', 'http://twitter.com/search?q=%23',
            None, 'http://www.twitter.com')
        
        self.http = TwitterHTTP(self.apiurl)
        self.retweet_by_me = []
        self.oauth_support = False
        
    def __get_real_tweet(self, tweet):
        '''Get the tweet retweeted'''
        retweet_by = None
        real_timestamp = None
        if tweet.has_key('retweeted_status'):
            retweet_by = tweet['user']['screen_name']
            real_timestamp = tweet['created_at']
            tweet = tweet['retweeted_status']
            
        return tweet, retweet_by, real_timestamp
        
    def __print_you(self, username):
        ''' Print "you" if username is the name of the user'''
        if username == self.profile.username:
            return 'you'
        else:
            return username
    
    def __create_status(self, resp, type=UPDATE_TYPE_STD):
        tweet, retweet_by, real_timestamp = self.__get_real_tweet(resp)
        
        if tweet.has_key('user'):
            username = tweet['user']['screen_name']
            avatar = tweet['user']['profile_image_url']
        elif tweet.has_key('sender'):
            username = tweet['sender']['screen_name']
            avatar = tweet['sender']['profile_image_url']
        elif tweet.has_key('from_user'):
            username = tweet['from_user']
            avatar = tweet['profile_image_url']
        
        in_reply_to_id = None
        in_reply_to_user = None
        if (tweet.has_key('in_reply_to_status_id') and
           tweet['in_reply_to_status_id']):
            in_reply_to_id = tweet['in_reply_to_status_id']
            in_reply_to_user = tweet['in_reply_to_screen_name']
            
        fav = False
        if tweet.has_key('favorited'):
            fav = tweet['favorited']
        source = None
        if tweet.has_key('source'):
            source = tweet['source']
        
        if username.lower() == self.profile.username.lower():
            own = True
        else:
            own = False
            
        if not real_timestamp:
            real_timestamp = tweet['created_at']
        
        status = Status()
        status.id = str(tweet['id'])
        status.username = username
        status.avatar = avatar
        status.source = source
        status.text = tweet['text']
        status.in_reply_to_id = in_reply_to_id
        status.in_reply_to_user = in_reply_to_user
        status.is_favorite = fav
        status.retweet_by = retweet_by
        status.datetime = self.get_str_time(tweet['created_at'])
        status.timestamp = self.get_int_time(real_timestamp)
        status.type = type
        status.protocol = PROTOCOLS[0]
        status.is_own = own
        return status
        
    def __create_profile(self, pf):
        profile = Profile()
        profile.id = pf['id']
        profile.fullname = pf['name']
        profile.username = pf['screen_name']
        profile.avatar = pf['profile_image_url']
        profile.location = pf['location']
        profile.url = pf['url']
        profile.bio = pf['description']
        profile.following = pf['following']
        profile.followers_count = pf['followers_count']
        profile.friends_count = pf['friends_count']
        profile.statuses_count = pf['statuses_count']
        if pf.has_key('status'):
            profile.last_update = pf['status']['text']
            profile.last_update_id = pf['status']['id']
        profile.profile_link_color = ('#%s' % pf['profile_link_color']) or '#0F0F85'
        return profile
        
    def __create_list(self, ls):
        _list = List()
        _list.id = ls['id']
        _list.slug = ls['slug']
        _list.name = ls['name']
        _list.mode = ls['mode']
        _list.user = ls['user']['screen_name']
        _list.member_count = ls['member_count']
        _list.description = ls['description']
        return _list
        
    def __create_rate(self, rl):
        rate = RateLimit()
        rate.hourly_limit = rl['hourly_limit']
        rate.remaining_hits = rl['remaining_hits']
        rate.reset_time = rl['reset_time']
        rate.reset_time_in_seconds = rl['reset_time_in_seconds']
        return rate
        
    def __get_retweet_users(self, id):
        users = ''
        try:
            rts = self.http.request('%s/statuses/%s/retweeted_by' % 
                (self.apiurl, id))
            
            results = self.response_to_profiles(rts)
            if len(results) == 1:
                users = self.__print_you(results[0].username)
            else:
                length = len(results)
                limit = 2 if length > 3 else length - 1
                
                for index in range(limit):
                    users += self.__print_you(results[index].username) + ', '
                
                if length > 3:
                    tail = ' and %i others' % (length - limit)
                else:
                    tail = ' and %s' % self.__print_you(results[limit].username)
                users = users[:-2] + tail
        except Exception, exc:
            print exc
        
        return users
Example #4
0
class Twitter(Protocol):
    def __init__(self):
        Protocol.__init__(self, 'Twitter', 'http://api.twitter.com/1',
                          'http://search.twitter.com',
                          'http://twitter.com/search?q=%23', None,
                          'http://www.twitter.com')

        self.http = TwitterHTTP(self.apiurl)
        self.retweet_by_me = []
        self.oauth_support = False

    def __get_real_tweet(self, tweet):
        '''Get the tweet retweeted'''
        retweet_by = None
        real_timestamp = None
        if tweet.has_key('retweeted_status'):
            retweet_by = tweet['user']['screen_name']
            real_timestamp = tweet['created_at']
            tweet = tweet['retweeted_status']

        return tweet, retweet_by, real_timestamp

    def __print_you(self, username):
        ''' Print "you" if username is the name of the user'''
        if username == self.profile.username:
            return 'you'
        else:
            return username

    def __create_status(self, resp, type=UPDATE_TYPE_STD):
        tweet, retweet_by, real_timestamp = self.__get_real_tweet(resp)

        if tweet.has_key('user'):
            username = tweet['user']['screen_name']
            avatar = tweet['user']['profile_image_url']
        elif tweet.has_key('sender'):
            username = tweet['sender']['screen_name']
            avatar = tweet['sender']['profile_image_url']
        elif tweet.has_key('from_user'):
            username = tweet['from_user']
            avatar = tweet['profile_image_url']

        in_reply_to_id = None
        in_reply_to_user = None
        if (tweet.has_key('in_reply_to_status_id')
                and tweet['in_reply_to_status_id']):
            in_reply_to_id = tweet['in_reply_to_status_id']
            in_reply_to_user = tweet['in_reply_to_screen_name']

        fav = False
        if tweet.has_key('favorited'):
            fav = tweet['favorited']
        source = None
        if tweet.has_key('source'):
            source = tweet['source']

        if username.lower() == self.profile.username.lower():
            own = True
        else:
            own = False

        if not real_timestamp:
            real_timestamp = tweet['created_at']

        status = Status()
        status.id = str(tweet['id'])
        status.username = username
        status.avatar = avatar
        status.source = source
        status.text = tweet['text']
        status.in_reply_to_id = in_reply_to_id
        status.in_reply_to_user = in_reply_to_user
        status.is_favorite = fav
        status.retweet_by = retweet_by
        status.datetime = self.get_str_time(tweet['created_at'])
        status.timestamp = self.get_int_time(real_timestamp)
        status.type = type
        status.protocol = PROTOCOLS[0]
        status.is_own = own
        return status

    def __create_profile(self, pf):
        profile = Profile()
        profile.id = pf['id']
        profile.fullname = pf['name']
        profile.username = pf['screen_name']
        profile.avatar = pf['profile_image_url']
        profile.location = pf['location']
        profile.url = pf['url']
        profile.bio = pf['description']
        profile.following = pf['following']
        profile.followers_count = pf['followers_count']
        profile.friends_count = pf['friends_count']
        profile.statuses_count = pf['statuses_count']
        if pf.has_key('status'):
            profile.last_update = pf['status']['text']
            profile.last_update_id = pf['status']['id']
        profile.profile_link_color = ('#%s' %
                                      pf['profile_link_color']) or '#0F0F85'
        return profile

    def __create_list(self, ls):
        _list = List()
        _list.id = ls['id']
        _list.slug = ls['slug']
        _list.name = ls['name']
        _list.mode = ls['mode']
        _list.user = ls['user']['screen_name']
        _list.member_count = ls['member_count']
        _list.description = ls['description']
        return _list

    def __create_rate(self, rl):
        rate = RateLimit()
        rate.hourly_limit = rl['hourly_limit']
        rate.remaining_hits = rl['remaining_hits']
        rate.reset_time = rl['reset_time']
        rate.reset_time_in_seconds = rl['reset_time_in_seconds']
        return rate

    def __get_retweet_users(self, id):
        users = ''
        try:
            rts = self.http.request('%s/statuses/%s/retweeted_by' %
                                    (self.apiurl, id))

            results = self.response_to_profiles(rts)
            if len(results) == 1:
                users = self.__print_you(results[0].username)
            else:
                length = len(results)
                limit = 2 if length > 3 else length - 1

                for index in range(limit):
                    users += self.__print_you(results[index].username) + ', '

                if length > 3:
                    tail = ' and %i others' % (length - limit)
                else:
                    tail = ' and %s' % self.__print_you(
                        results[limit].username)
                users = users[:-2] + tail
        except Exception, exc:
            print exc

        return users