delete unused break
[rainbowstream.git] / rainbowstream / rainbow.py
index 5542ca7ba6947184fd0af8183471095df9f94d02..fa66626634ab1f68061374f0d8892ae10e9cbf60 100644 (file)
@@ -122,6 +122,7 @@ def init(args):
     name = credential['name']
     if not get_config('PREFIX'):
         set_config('PREFIX', screen_name)
+    g['PREFIX'] = u2str(c['PREFIX'])
     c['original_name'] = g['original_name'] = screen_name[1:]
     g['full_name'] = name
     g['decorated_name'] = lambda x: color_func(
@@ -249,13 +250,24 @@ def search():
     Search
     """
     t = Twitter(auth=authen())
-    g['stuff'] = g['stuff'].strip()
-    rel = t.search.tweets(q=g['stuff'])['statuses']
+    # Setup query
+    query = g['stuff'].strip()
+    type = c['SEARCH_TYPE']
+    if type not in ['mixed', 'recent', 'popular']:
+        type = 'mixed'
+    max_record = c['SEARCH_MAX_RECORD']
+    count = min(max_record, 100)
+    # Perform search
+    rel = t.search.tweets(
+        q=query,
+        type=type,
+        count=count
+    )['statuses']
+    # Return results
     if rel:
         printNicely('Newest tweets:')
-        for i in reversed(xrange(c['SEARCH_MAX_RECORD'])):
-            draw(t=rel[i],
-                 keyword=g['stuff'])
+        for i in reversed(xrange(count)):
+            draw(t=rel[i], keyword=query)
         printNicely('')
     else:
         printNicely(magenta('I\'m afraid there is no result'))
@@ -461,10 +473,9 @@ def urlopen():
             return
         tid = c['tweet_dict'][int(g['stuff'])]
         tweet = t.statuses.show(id=tid)
-        link_ary = [
-            u for u in tweet['text'].split() if u.startswith('http://')]
-        link_ary.extend([
-            u for u in tweet['text'].split() if u.startswith('https://')])
+        link_prefix = ('http://', 'https://')
+        link_ary = [u for u in tweet['text'].split()
+                    if u.startswith(link_prefix)]
         if not link_ary:
             printNicely(light_magenta('No url here @.@!'))
             return
@@ -1690,7 +1701,7 @@ def listen():
         try:
             # raw_input
             if g['prefix']:
-                line = raw_input(g['decorated_name'](c['PREFIX']))
+                line = raw_input(g['decorated_name'](g['PREFIX']))
             else:
                 line = raw_input()
             # Save cmd to compare with readline buffer
@@ -1774,7 +1785,7 @@ def stream(domain, args, name='Rainbow Stream'):
                     light_green("h stream") + \
                     light_magenta(" for more details.")
                 printNicely(guide)
-                sys.stdout.write(g['decorated_name'](c['PREFIX']))
+                sys.stdout.write(g['decorated_name'](g['PREFIX']))
                 sys.stdout.flush()
                 StreamLock.release()
                 break
@@ -1802,10 +1813,10 @@ def stream(domain, args, name='Rainbow Stream'):
                 # the 1st character of that word
                 if current_buffer and g['cmd'] != current_buffer:
                     sys.stdout.write(
-                        g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
+                        g['decorated_name'](g['PREFIX']) + str2u(current_buffer))
                     sys.stdout.flush()
                 elif not c['HIDE_PROMPT']:
-                    sys.stdout.write(g['decorated_name'](c['PREFIX']))
+                    sys.stdout.write(g['decorated_name'](g['PREFIX']))
                     sys.stdout.flush()
             elif tweet.get('direct_message'):
                 # Check the semaphore pause and lock (stream process only)