Twitter Error display bug in Python 3
[rainbowstream.git] / rainbowstream / rainbow.py
index 06bdd5420f4a5c803148f41821b9fd10275bb384..f06b510aa708d39896a8fa0ef1f07ba9b7b15514 100644 (file)
@@ -27,6 +27,7 @@ from .interactive import *
 from .c_image import *
 from .py3patch import *
 from .emoji import *
 from .c_image import *
 from .py3patch import *
 from .emoji import *
+from .util import *
 
 # Global values
 g = {}
 
 # Global values
 g = {}
@@ -178,6 +179,11 @@ def upgrade_center():
             notice += light_magenta('You should upgrade with ')
             notice += light_green('pip install -U rainbowstream')
             printNicely(notice)
             notice += light_magenta('You should upgrade with ')
             notice += light_green('pip install -U rainbowstream')
             printNicely(notice)
+        else:
+            notice = light_yellow('You are running latest version (')
+            notice += light_green(current)
+            notice += light_yellow(')')
+            printNicely(notice)
     except:
         pass
 
     except:
         pass
 
@@ -1660,6 +1666,7 @@ def help():
     usage += s * 2 + light_green('p') + ' will pause the stream.\n'
     usage += s * 2 + light_green('r') + ' will unpause the stream.\n'
     usage += s * 2 + light_green('c') + ' will clear the screen.\n'
     usage += s * 2 + light_green('p') + ' will pause the stream.\n'
     usage += s * 2 + light_green('r') + ' will unpause the stream.\n'
     usage += s * 2 + light_green('c') + ' will clear the screen.\n'
+    usage += s * 2 + light_green('v') + ' will show version info.\n'
     usage += s * 2 + light_green('q') + ' will quit.\n'
     # End
     usage += '\n'
     usage += s * 2 + light_green('q') + ' will quit.\n'
     # End
     usage += '\n'
@@ -1778,7 +1785,8 @@ cmdset = [
     'p',
     'r',
     'c',
     'p',
     'r',
     'c',
-    'q'
+    'v',
+    'q',
 ]
 
 # Handle function set
 ]
 
 # Handle function set
@@ -1824,7 +1832,8 @@ funcset = [
     pause,
     replay,
     clear,
     pause,
     replay,
     clear,
-    quit
+    upgrade_center,
+    quit,
 ]
 
 
 ]
 
 
@@ -1902,6 +1911,7 @@ def listen():
             [],  # pause
             [],  # reconnect
             [],  # clear
             [],  # pause
             [],  # reconnect
             [],  # clear
+            [],  # version
             [],  # quit
         ]
     ))
             [],  # quit
         ]
     ))
@@ -1997,6 +2007,7 @@ def stream(domain, args, name='Rainbow Stream'):
         # Block new stream until other one exits
         StreamLock.acquire()
         g['stream_stop'] = False
         # Block new stream until other one exits
         StreamLock.acquire()
         g['stream_stop'] = False
+        last_tweet_time = time.time()
         for tweet in tweet_iter:
             if tweet is None:
                 printNicely("-- None --")
         for tweet in tweet_iter:
             if tweet is None:
                 printNicely("-- None --")
@@ -2017,6 +2028,10 @@ def stream(domain, args, name='Rainbow Stream'):
                 StreamLock.release()
                 break
             elif tweet.get('text'):
                 StreamLock.release()
                 break
             elif tweet.get('text'):
+                # Slow down the stream by STREAM_DELAY config key
+                if time.time() - last_tweet_time < c['STREAM_DELAY']:
+                    continue
+                last_tweet_time = time.time()
                 # Check the semaphore pause and lock (stream process only)
                 if g['pause']:
                     continue
                 # Check the semaphore pause and lock (stream process only)
                 if g['pause']:
                     continue
@@ -2053,10 +2068,13 @@ def stream(domain, args, name='Rainbow Stream'):
             elif tweet.get('event'):
                 c['events'].append(tweet)
                 print_event(tweet)
             elif tweet.get('event'):
                 c['events'].append(tweet)
                 print_event(tweet)
-    except TwitterHTTPError:
+    except TwitterHTTPError as e:
         printNicely('')
         printNicely(
         printNicely('')
         printNicely(
-            magenta("We have maximum connection problem with twitter'stream API right now :("))
+            magenta("We have connection problem with twitter'stream API right now :("))
+        detail_twitter_error(e)
+        sys.stdout.write(g['decorated_name'](c['PREFIX']))
+        sys.stdout.flush()
 
 
 def fly():
 
 
 def fly():
@@ -2069,11 +2087,11 @@ def fly():
         proxy_connect(args)
         init(args)
     # Twitter API connection problem
         proxy_connect(args)
         init(args)
     # Twitter API connection problem
-    except TwitterHTTPError:
+    except TwitterHTTPError as e:
         printNicely('')
         printNicely(
         printNicely('')
         printNicely(
-            magenta("We have connection problem with twitter'stream API right now :("))
-        printNicely(magenta("Let's try again later."))
+            magenta("We have connection problem with twitter'REST API right now :("))
+        detail_twitter_error(e)
         save_history()
         sys.exit()
     # Proxy connection problem
         save_history()
         sys.exit()
     # Proxy connection problem