Fix some bugs by pull requests
[rainbowstream.git] / rainbowstream / rainbow.py
index 578754f12ce6ae0ba83f83a01a352e2234059d66..3a55c18ab5a6c06e058e021133a26654f292ea37 100644 (file)
@@ -44,7 +44,7 @@ def parse_arguments():
     parser.add_argument(
         '-s',
         '--stream',
-             default="mine",
+        default="mine",
         help='Default stream after program start. (Default: mine)')
     parser.add_argument(
         '-to',
@@ -239,7 +239,6 @@ def init(args):
     c['message_dict'] = []
     # Image on term
     c['IMAGE_ON_TERM'] = args.image_on_term
-    set_config('IMAGE_ON_TERM', str(c['IMAGE_ON_TERM']))
     # Use 24 bit color
     c['24BIT'] = args.color_24bit
     # Check type of ONLY_LIST and IGNORE_LIST
@@ -373,6 +372,21 @@ def view():
         printNicely(red('A name should begin with a \'@\''))
 
 
+def view_my_tweets():
+    """
+    Display user's recent tweets.
+    """
+    t = Twitter(auth=authen())
+    try:
+        num = int(g['stuff'])
+    except:
+        num = c['HOME_TWEET_NUM']
+    for tweet in reversed(
+            t.statuses.user_timeline(count=num, screen_name=g['original_name'])):
+        draw(t=tweet)
+    printNicely('')
+
+
 def search():
     """
     Search
@@ -657,7 +671,7 @@ def urlopen():
             return
         else:
             for url in urls:
-                expanded_url = url['expanded_url'] 
+                expanded_url = url['expanded_url']
                 webbrowser.open(expanded_url)
     except:
         debug_option()
@@ -868,7 +882,7 @@ def mute():
             rel = t.mutes.users.create(screen_name=screen_name[1:])
             if isinstance(rel, dict):
                 printNicely(green(screen_name + ' is muted.'))
-                c['IGNORE_LIST'] += [unc(screen_name)]
+                c['IGNORE_LIST'] += [screen_name]
                 c['IGNORE_LIST'] = list(set(c['IGNORE_LIST']))
             else:
                 printNicely(red(rel))
@@ -1438,6 +1452,8 @@ def help_discover():
         light_green('trend JP Tokyo') + '.\n'
     usage += s * 2 + light_green('home') + ' will show your timeline. ' + \
         light_green('home 7') + ' will show 7 tweets.\n'
+    usage += s * 2 + light_green('me') + ' will show your latest tweets. ' + \
+        light_green('me 2') + ' will show your last 2 tweets.\n'
     usage += s * 2 + \
         light_green('notification') + ' will show your recent notification.\n'
     usage += s * 2 + light_green('mentions') + ' will show mentions timeline. ' + \
@@ -1762,6 +1778,7 @@ cmdset = [
     't',
     'rt',
     'quote',
+    'me',
     'allrt',
     'conversation',
     'fav',
@@ -1810,6 +1827,7 @@ funcset = [
     tweet,
     retweet,
     quote,
+    view_my_tweets,
     allretweet,
     conversation,
     favorite,
@@ -1871,6 +1889,7 @@ def listen():
             [],  # tweet
             [],  # retweet
             [],  # quote
+            [],  # view_my_tweets
             [],  # allretweet
             [],  # conversation
             [],  # favorite
@@ -1950,33 +1969,23 @@ def listen():
             # Save cmd to global variable and call process
             g['stuff'] = ' '.join(line.split()[1:])
             # Check tweet length
-            if check_tweet_length():
-                # Process the command
-                process(cmd)()
-                # Not re-display
-                if cmd in ['switch', 't', 'rt', 'rep']:
-                    g['prefix'] = False
-                else:
-                    g['prefix'] = True
-            # Release the semaphore lock
-            c['lock'] = False
+            # Process the command
+            process(cmd)()
+            # Not re-display
+            if cmd in ['switch', 't', 'rt', 'rep']:
+                g['prefix'] = False
+            else:
+                g['prefix'] = True
         except EOFError:
             printNicely('')
+        except TwitterHTTPError as e:
+            detail_twitter_error(e)
         except Exception:
             debug_option()
-            printNicely(red('OMG something is wrong with Twitter right now.'))
-
-
-def check_tweet_length():
-    """
-    Check tweet length (should be <= 140 chars)
-    """
-    length = len(g['stuff'])
-    if length <= 140:
-        return True
-
-    printNicely(red("Message is too long: %s chars" % length))
-    return False
+            printNicely(red('OMG something is wrong with Twitter API right now.'))
+        finally:
+            # Release the semaphore lock
+            c['lock'] = False
 
 
 def reconn_notice():
@@ -2231,7 +2240,7 @@ def fly():
 
     # Spawn stream thread
     target = args.stream.split()[0]
-    if target == 'mine' :
+    if target == 'mine':
         spawn_personal_stream(args)
     else:
         try: