def get_timeline(self, url, url_params): ents = HTMLParser.HTMLParser() tweet_id = 0 credentials = oauth.connection() twitter_request = requests.get(url, auth=credentials, params=url_params) if twitter_request.json() and twitter_request.status_code == 200: ref = self.page self.page += 1 self.timeline.append(twitter_request.json()) self.since_id = self.timeline[ref][0]['id_str'] for i in range(len(self.timeline[ref])-1, -1, -1): tweet_id += 1 try: text = ents.unescape(self.timeline[ref][i]['retweeted_status']['text']) print '%d %d %s from %s' % ( self.page, tweet_id, colored.green('@' + self.timeline[ref][i]['user']['screen_name']), colored.red('@' + self.timeline[ref][i]['retweeted_status']['user']['screen_name']) ) print colored.yellow(text) print '' except KeyError: text = ents.unescape(self.timeline[ref][i]['text']) print '%d %d %s' % ( self.page, tweet_id, colored.green('@' + self.timeline[ref][i]['user']['screen_name']) ) print colored.yellow(text) print '' else: print colored.red('Theres no new tweets at the moment !!!')
def warning(message, prefix, label='WARNING: '): print prefix + colored.yellow(label) + message