From: Orakaro Date: Fri, 4 Jul 2014 00:55:01 +0000 (+0900) Subject: add calendar and calculator support in theme X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2a0cabee7d64c340ffa722472098c00aff2c1361;p=rainbowstream.git add calendar and calculator support in theme --- diff --git a/rainbowstream/colorset/default.json b/rainbowstream/colorset/default.json index 593321a..9e0a6ab 100644 --- a/rainbowstream/colorset/default.json +++ b/rainbowstream/colorset/default.json @@ -79,5 +79,10 @@ "TREND" : { "url": "light_cyan" + }, + + "CAL" : { + "days": "grey", + "today": "on_grey" } } \ No newline at end of file diff --git a/rainbowstream/colorset/monokai.json b/rainbowstream/colorset/monokai.json index 06f508b..50eafb9 100644 --- a/rainbowstream/colorset/monokai.json +++ b/rainbowstream/colorset/monokai.json @@ -54,5 +54,10 @@ "TREND" : { "url": "term_74" + }, + + "CAL" : { + "days": "term_57", + "today": "on_light_blue" } } \ No newline at end of file diff --git a/rainbowstream/colorset/solarized.json b/rainbowstream/colorset/solarized.json index 83c9d85..5b85209 100644 --- a/rainbowstream/colorset/solarized.json +++ b/rainbowstream/colorset/solarized.json @@ -54,5 +54,10 @@ "TREND" : { "url": "term_23" + }, + + "CAL" : { + "days": "term_64", + "today": "on_light_green" } } \ No newline at end of file diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 27cc874..bdeafdf 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -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 diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 98aa05f..fe060fb 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -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() diff --git a/setup.py b/setup.py index 5a62f33..8a6b534 100644 --- 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",