def __init__(self): Protocol.__init__(self, 'Identi.ca', 'https://identi.ca/api', 'http://identi.ca/api', 'http://identi.ca/tag/', 'http://identi.ca/group', 'http://identi.ca') self.http = IdenticaHTTP() self.retweet_by_me = []
def __init__(self): Protocol.__init__(self, 'Identi.ca', 'http://identi.ca/api', 'http://identi.ca/api', 'http://identi.ca/tag/', 'http://identi.ca/group', 'http://identi.ca') self.http = IdenticaHTTP() self.retweet_by_me = []
class Identica(Protocol): def __init__(self): Protocol.__init__(self, 'Identi.ca', 'http://identi.ca/api', 'http://identi.ca/api', 'http://identi.ca/tag/', 'http://identi.ca/group', 'http://identi.ca') self.http = IdenticaHTTP() self.retweet_by_me = [] def __get_real_tweet(self, tweet): '''Get the tweet retweeted''' retweet_by = None if tweet.has_key('retweeted_status'): retweet_by = tweet['user']['screen_name'] tweet = tweet['retweeted_status'] return tweet, retweet_by def __print_you(self, username): ''' Print "you" is 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 = 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 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(tweet['created_at']) status.type = type status.protocol = PROTOCOLS[1] 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'] profile.profile_link_color = pf['profile_link_color'] or '#0F0F85' return profile 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
class Identica(Protocol): def __init__(self): Protocol.__init__(self, 'Identi.ca', 'https://identi.ca/api', 'http://identi.ca/api', 'http://identi.ca/tag/', 'http://identi.ca/group', 'http://identi.ca') self.http = IdenticaHTTP() self.retweet_by_me = [] def __get_real_tweet(self, tweet): '''Get the tweet retweeted''' retweet_by = None if tweet.has_key('retweeted_status'): retweet_by = tweet['user']['screen_name'] tweet = tweet['retweeted_status'] return tweet, retweet_by def __print_you(self, username): ''' Print "you" is 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 = 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 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(tweet['created_at']) status.type = type status.protocol = PROTOCOLS[1] 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'] profile.profile_link_color = '#0F0F85' return profile 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