Delete unused Error
[rainbowstream.git] / rainbowstream / rainbow.py
index a2c80e7..53fcd63 100644 (file)
@@ -324,7 +324,11 @@ def whois():
     Show profile of a specific user
     """
     t = Twitter(auth=authen())
-    screen_name = g['stuff'].split()[0]
+    try:
+        screen_name = g['stuff'].split()[0]
+    except:
+        printNicely(red('Sorry I can\'t understand.'))
+        return
     if screen_name.startswith('@'):
         try:
             user = t.users.show(
@@ -343,7 +347,11 @@ def view():
     Friend view
     """
     t = Twitter(auth=authen())
-    user = g['stuff'].split()[0]
+    try:
+        user = g['stuff'].split()[0]
+    except:
+        printNicely(red('Sorry I can\'t understand.'))
+        return
     if user[0] == '@':
         try:
             num = int(g['stuff'].split()[1])
@@ -364,6 +372,9 @@ def search():
     t = Twitter(auth=authen())
     # Setup query
     query = g['stuff'].strip()
+    if not query:
+        printNicely(red('Sorry I can\'t understand.'))
+        return
     type = c['SEARCH_TYPE']
     if type not in ['mixed', 'recent', 'popular']:
         type = 'mixed'
@@ -519,11 +530,13 @@ def reply_all():
     tid = c['tweet_dict'][id]
     original_tweet = t.statuses.show(id=tid)
     text = original_tweet['text']
-    owner = '@' + original_tweet['user']['screen_name']
-    nick_ary = ['@' + re.sub('[\W_]', '', w)
-                for w in text.split() if w.startswith('@')] + [owner]
+    nick_ary = [original_tweet['user']['screen_name']]
+    for user in list(original_tweet['entities']['user_mentions']):
+        if user['screen_name'] not in nick_ary \
+                and user['screen_name'] != g['original_name']:
+            nick_ary.append(user['screen_name'])
     status = ' '.join(g['stuff'].split()[1:])
-    status = ' '.join(nick_ary) + ' ' + str2u(status)
+    status = ' '.join(['@' + nick for nick in nick_ary]) + ' ' + str2u(status)
     t.statuses.update(status=status, in_reply_to_status_id=tid)
 
 
@@ -780,6 +793,7 @@ def ls():
         target = g['stuff'].split()[0]
     except:
         printNicely(red('Omg some syntax is wrong.'))
+        return
     # Init cursor
     d = {'fl': 'followers', 'fr': 'friends'}
     next_cursor = -1
@@ -1965,7 +1979,7 @@ def stream(domain, args, name='Rainbow Stream'):
     # The Logo
     art_dict = {
         c['USER_DOMAIN']: name,
-        c['PUBLIC_DOMAIN']: args.track_keywords,
+        c['PUBLIC_DOMAIN']: args.track_keywords or 'Global',
         c['SITE_DOMAIN']: name,
     }
     if c['ASCII_ART']:
@@ -2065,7 +2079,7 @@ def stream(domain, args, name='Rainbow Stream'):
         detail_twitter_error(e)
         sys.stdout.write(g['decorated_name'](g['PREFIX']))
         sys.stdout.flush()
-    except (URLError, ConnectionResetError):
+    except (URLError):
         printNicely(
             magenta('There seems to be a connection problem.'))
         save_history()
@@ -2081,11 +2095,11 @@ def spawn_public_stream(args, keyword=None):
         if keyword[0] == '#':
             keyword = keyword[1:]
         args.track_keywords = keyword
-    # Set the variable to tracked keyword
-    g['keyword'] = keyword
-    g['listname'] = ''
-    # Reset prefix
+        g['keyword'] = keyword
+    else:
+        g['keyword'] = 'Global'
     g['PREFIX'] = u2str(emojize(format_prefix(keyword=g['keyword'])))
+    g['listname'] = ''
     # Start new thread
     th = threading.Thread(
         target=stream,
@@ -2104,7 +2118,7 @@ def spawn_list_stream(args, stuff=None):
         owner, slug = check_slug(stuff)
     except:
         owner, slug = get_slug()
-    
+
     # Force python 2 not redraw readline buffer
     listname = '/'.join([owner, slug])
     # Set the listname variable
@@ -2197,18 +2211,17 @@ def fly():
     target = args.stream.split()[0]
     if target == 'mine' :
         spawn_personal_stream(args)
-    else :
+    else:
         try:
             stuff = args.stream.split()[1]
-            spawn_dict = {
-                'public': spawn_public_stream,
-                'list': spawn_list_stream,
-            }
-            spawn_dict.get(target)(args, stuff)
         except:
-            printNicely(red('Wrong -s/--stream argument given. Loading your personal stream.'))
-            spawn_personal_stream(args)
-    
+            stuff = None
+        spawn_dict = {
+            'public': spawn_public_stream,
+            'list': spawn_list_stream,
+        }
+        spawn_dict.get(target)(args, stuff)
+
     # Start listen process
     time.sleep(0.5)
     g['reset'] = True