db = RainbowDB()
g = {}
-
def init_cycle():
"""
Init the 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)
"""
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)
))
+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
# 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():
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
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']:
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 --")
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():
"""
# 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()