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 main(): tweetcommander = twitter.tweetcommander(); # Print welcome screen tweetcommander.welcome() # if the tweetcomm.db file doesn't exists # in your ~/.config/tweetcommander path # then it executes the oauth authentication if not os.path.exists(db_path): first_time_oauth() print 'Now you can use TweeтCoммander.' db_exists = True else: db_exists = True # core loop of the application takes an input option and print the results while db_exists: # if eveything is ok tweetcommader waits for an input option action = raw_input(colored.red('> ')) # if no action or non valid input print error message tweetcommander.commands(action)
def error(message, prefix, label='ERROR: '): print prefix + colored.red(label) + message