- # When using twitter stream you must authorize.
- oauth_filename = os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.twitter_oauth'
- oauth_token, oauth_token_secret = read_token_file(oauth_filename)
- auth = OAuth(oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET)
+def get_decorated_name():
+ """
+ Beginning of every line
+ """
+ t = Twitter(auth=authen())
+ name = '@' + t.statuses.user_timeline()[-1]['user']['screen_name']
+ g['decorated_name'] = grey('[') + grey(name) + grey(']: ')
+
+
+def home():
+ """
+ Home
+ """
+ t = Twitter(auth=authen())
+ count = HOME_TWEET_NUM
+ if g['stuff'].isdigit():
+ count = g['stuff']
+ for tweet in reversed(t.statuses.home_timeline(count=count)):
+ draw(t=tweet)
+
+
+def view():
+ """
+ Friend view
+ """
+ t = Twitter(auth=authen())
+ user = g['stuff'].split()[0]
+ try:
+ count = int(g['stuff'].split()[1])
+ except:
+ count = HOME_TWEET_NUM
+ for tweet in reversed(t.statuses.user_timeline(count=count, screen_name=user)):
+ draw(t=tweet)
+
+
+def tweet():
+ """
+ Tweet
+ """
+ t = Twitter(auth=authen())
+ t.statuses.update(status=g['stuff'])
+
+
+def reply():
+ """
+ Reply
+ """
+ t = Twitter(auth=authen())
+ try:
+ id = int(g['stuff'].split()[0])
+ user = t.statuses.show(id=id)['user']['screen_name']
+ status = ' '.join(g['stuff'].split()[1:])
+ status = '@' + user + ' ' + status.decode('utf-8')
+ t.statuses.update(status=status, in_reply_to_status_id=id)
+ except:
+ print(red('Sorry I can\'t understand.'))
+
+
+def delete():
+ """
+ Delete
+ """
+ t = Twitter(auth=authen())
+ try:
+ id = int(g['stuff'].split()[0])
+ t.statuses.destroy(id=id)
+ print(green('Okay it\'s gone.'))
+ except:
+ print(red('Sorry I can\'t delete this tweet for you.'))
+
+
+def search():
+ """
+ Search
+ """
+ t = Twitter(auth=authen())
+ rel = t.search.tweets(q='#' + g['stuff'])['statuses']
+ h, w = os.popen('stty size', 'r').read().split()
+
+ printNicely(grey('*' * int(w) + '\n'))
+ print('Newest', SEARCH_MAX_RECORD, 'tweet: \n')
+ for i in xrange(5):
+ draw(t=rel[i], keyword=g['stuff'].strip())
+ printNicely(grey('*' * int(w) + '\n'))