add calendar and calculator support in theme
authorOrakaro <nhatminh_179@hotmail.com>
Fri, 4 Jul 2014 00:55:01 +0000 (09:55 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Fri, 4 Jul 2014 00:55:01 +0000 (09:55 +0900)
rainbowstream/colorset/default.json
rainbowstream/colorset/monokai.json
rainbowstream/colorset/solarized.json
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

index 593321ad88933fbe5bf840d7d9305d752a40220e..9e0a6abdfacef4380cd00904caf5f657e343d182 100644 (file)
 
     "TREND" : {
         "url": "light_cyan"
+    },
+
+    "CAL" : {
+        "days": "grey",
+        "today": "on_grey"
     }
 }
\ No newline at end of file
index 06f508b6e09065b0c6bded7d5e585539de9ca9aa..50eafb9da23c86f0d442a8e716b3e78c4470e3d6 100644 (file)
 
     "TREND" : {
         "url": "term_74"
+    },
+
+    "CAL" : {
+        "days": "term_57",
+        "today": "on_light_blue"
     }
 }
\ No newline at end of file
index 83c9d85608aaf60b6b69a45b1a051067db8e6327..5b852091997e55a2de8940b3273f170f57c3fd52 100644 (file)
 
     "TREND" : {
         "url": "term_23"
+    },
+
+    "CAL" : {
+        "days": "term_64",
+        "today": "on_light_green"
     }
 }
\ No newline at end of file
index 27cc8746865e784f97d0bace7289831c9f734423..bdeafdfc77ca8ce01d308c05d94b070d39156a2a 100644 (file)
@@ -18,7 +18,6 @@ from .db import *
 db = RainbowDB()
 g = {}
 
-
 def init_cycle():
     """
     Init the cycle
@@ -27,22 +26,22 @@ def init_cycle():
         if not i.startswith('term_')
         else term_color(int(i[5:]))
         for i in c['CYCLE_COLOR']]
-    return itertools.cycle(colors_shuffle)
-g['cyc'] = init_cycle()
+    return colors_shuffle, itertools.cycle(colors_shuffle)
+g['colors_shuffle'], g['cyc'] = init_cycle()
 
 
 def notify_cycle():
     """
     Notify from rainbow
     """
-    g['cyc'] = init_cycle()
+    g['colors_shuffle'], g['cyc'] = init_cycle()
 
 
 def order_rainbow(s):
     """
     Print a string with ordered color with each character
     """
-    c = [colors_shuffle[i % 7](s[i]) for i in xrange(len(s))]
+    c = [g['colors_shuffle'][i % 7](s[i]) for i in xrange(len(s))]
     return reduce(lambda x, y: x + y, c)
 
 
@@ -50,7 +49,7 @@ def random_rainbow(s):
     """
     Print a string with random color with each character
     """
-    c = [random.choice(colors_shuffle)(i) for i in s]
+    c = [random.choice(g['colors_shuffle'])(i) for i in s]
     return reduce(lambda x, y: x + y, c)
 
 
@@ -86,6 +85,25 @@ def ascii_art(text):
     ))
 
 
+def show_calendar(month, date, rel):
+    """
+    Show the calendar in rainbow mode
+    """
+    month = random_rainbow(month)
+    date = ' '.join([cycle_color(i) for i in date.split(' ')])
+    today = str(int(os.popen('date +\'%d\'').read().strip()))
+    # Display
+    printNicely(month)
+    printNicely(date)
+    for line in rel:
+        ary = line.split(' ')
+        ary = map(lambda x: color_func(c['CAL']['today'])(x)
+            if x == today
+            else color_func(c['CAL']['days'])(x)
+            , ary)
+        printNicely(' '.join(ary))
+
+
 def check_theme():
     """
     Check current theme and update if necessary
index 98aa05fba3da2a6c2531ea10c9e6057b641dcfcb..fe060fb3de0af1a5e411ff50f166877644b7ae41 100644 (file)
@@ -751,17 +751,8 @@ def cal():
     # Format
     rel = os.popen('cal').read().split('\n')
     month = rel.pop(0)
-    month = random_rainbow(month)
     date = rel.pop(0)
-    date = ' '.join([cycle_color(i) for i in date.split(' ')])
-    today = str(int(os.popen('date +\'%d\'').read().strip()))
-    # Display
-    printNicely(month)
-    printNicely(date)
-    for line in rel:
-        ary = line.split(' ')
-        ary = map(lambda x: on_grey(x) if x == today else grey(x), ary)
-        printNicely(' '.join(ary))
+    show_calendar(month, date, rel)
 
 
 def theme():
@@ -984,8 +975,8 @@ def reset():
         printNicely(magenta('Need tips ? Type "h" and hit Enter key!'))
     g['reset'] = False
     try:
-        printNicely(eval(g['cmd']))
-    except:
+        printNicely(str(eval(g['cmd'])))
+    except Exception:
         pass
 
 
@@ -1092,8 +1083,7 @@ def listen():
         try:
             g['stuff'] = ' '.join(line.split()[1:])
             process(cmd)()
-        except Exception as e:
-            print e
+        except Exception:
             printNicely(red('OMG something is wrong with Twitter right now.'))
         # Not redisplay prefix
         if cmd in ['switch', 't', 'rt', 'rep']:
@@ -1133,18 +1123,18 @@ def stream(domain, args, name='Rainbow Stream'):
         domain=domain,
         **stream_args)
 
-    if domain == c['USER_DOMAIN']:
-        tweet_iter = stream.user(**query_args)
-    elif domain == c['SITE_DOMAIN']:
-        tweet_iter = stream.site(**query_args)
-    else:
-        if args.track_keywords:
-            tweet_iter = stream.statuses.filter(**query_args)
+    try:
+        if domain == c['USER_DOMAIN']:
+            tweet_iter = stream.user(**query_args)
+        elif domain == c['SITE_DOMAIN']:
+            tweet_iter = stream.site(**query_args)
         else:
-            tweet_iter = stream.statuses.sample()
+            if args.track_keywords:
+                tweet_iter = stream.statuses.filter(**query_args)
+            else:
+                tweet_iter = stream.statuses.sample()
 
-    # Iterate over the stream.
-    try:
+        # Iterate over the stream.
         for tweet in tweet_iter:
             if tweet is None:
                 printNicely("-- None --")
@@ -1162,10 +1152,10 @@ def stream(domain, args, name='Rainbow Stream'):
                     fil=args.filter,
                     ig=args.ignore,
                 )
-    except:
+    except TwitterHTTPError:
+        printNicely('')
         printNicely(
-            magenta("I'm afraid we have problem with twitter'S maximum connection."))
-        printNicely(magenta("Let's try again later."))
+            magenta("We have maximum connection problem with twitter'stream API right now :("))
 
 
 def fly():
@@ -1174,11 +1164,22 @@ def fly():
     """
     # Spawn stream process
     args = parse_arguments()
-    get_decorated_name()
+    try:
+        get_decorated_name()
+
+    except TwitterHTTPError:
+        printNicely('')
+        printNicely(
+            magenta("I'm afraid we have maximum connection problem with twitter right now :("))
+        printNicely(magenta("Let's try again later."))
+        save_history()
+        os.system('rm -rf rainbow.db')
+        sys.exit()
+
     p = Process(
         target=stream,
         args=(
-            c['USER_DOMAIN'],
+        c['USER_DOMAIN'],
             args,
             g['original_name']))
     p.start()
index 5a62f332964d000616c190118401302a8a4236c6..8a6b534f32f66d25221348b77109cb8750ae65da 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.1.6'
+version = '0.1.7'
 
 install_requires = [
     "SQLAlchemy",