From 8141aca6b2aaa7ce8f097f689fc2241f4f7ad3af Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Tue, 29 Jul 2014 18:56:13 +0900 Subject: [PATCH] refactoring some code --- docs/conf.py | 4 +-- rainbowstream/db.py | 14 -------- rainbowstream/draw.py | 70 +++++++++++++++++++++------------------- rainbowstream/rainbow.py | 2 +- setup.py | 8 +++-- 5 files changed, 44 insertions(+), 54 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e5b64fe..a94a094 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,9 +51,9 @@ copyright = u'2014, Vu Nhat Minh' # built documents. # # The short X.Y version. -version = '0.5.6' +version = '0.5.7' # The full version, including alpha/beta/rc tags. -release = '0.5.6' +release = '0.5.7' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/rainbowstream/db.py b/rainbowstream/db.py index 01b91fb..192448f 100644 --- a/rainbowstream/db.py +++ b/rainbowstream/db.py @@ -17,7 +17,6 @@ class RainbowDB(): init_db() self.engine = create_engine('sqlite:///rainbow.db', echo=False) - def tweet_store(self, tweet_id): """ Store tweet id @@ -28,7 +27,6 @@ class RainbowDB(): session.add(t) session.commit() - def rainbow_to_tweet_query(self, rid): """ Query base of rainbow id @@ -38,7 +36,6 @@ class RainbowDB(): res = session.query(Tweet).filter_by(rainbow_id=rid).all() return res - def tweet_to_rainbow_query(self, tid): """ Query base of tweet id @@ -48,7 +45,6 @@ class RainbowDB(): res = session.query(Tweet).filter_by(tweet_id=tid).all() return res - def message_store(self, message_id): """ Store message id @@ -59,7 +55,6 @@ class RainbowDB(): session.add(m) session.commit() - def rainbow_to_message_query(self, rid): """ Query base of rainbow id @@ -69,7 +64,6 @@ class RainbowDB(): res = session.query(Message).filter_by(rainbow_id=rid).all() return res - def message_to_rainbow_query(self, mid): """ Query base of message id @@ -79,7 +73,6 @@ class RainbowDB(): res = session.query(Message).filter_by(message_id=mid).all() return res - def theme_store(self, theme_name): """ Store theme @@ -90,7 +83,6 @@ class RainbowDB(): session.add(th) session.commit() - def theme_update(self, theme_name): """ Update theme @@ -102,7 +94,6 @@ class RainbowDB(): r.theme_name = theme_name session.commit() - def theme_query(self): """ Query theme @@ -112,7 +103,6 @@ class RainbowDB(): res = session.query(Theme).all() return res - def semaphore_store(self, lock, pause): """ Store semaphore lock @@ -123,7 +113,6 @@ class RainbowDB(): session.add(th) session.commit() - def semaphore_update_lock(self, lock): """ Update semaphore lock @@ -135,7 +124,6 @@ class RainbowDB(): r.lock = lock session.commit() - def semaphore_update_pause(self, pause): """ Update semaphore pause @@ -147,7 +135,6 @@ class RainbowDB(): r.pause = pause session.commit() - def semaphore_query_lock(self): """ Query semaphore lock @@ -157,7 +144,6 @@ class RainbowDB(): res = session.query(Semaphore).all() return res[0].lock - def semaphore_query_pause(self): """ Query semaphore pause diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 589d5f3..78c3a26 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -93,24 +93,6 @@ 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 = lmap(lambda x: color_func(c['CAL']['today'])(x) - if x == today - else color_func(c['CAL']['days'])(x), ary) - printNicely(' '.join(ary)) - - def check_config(): """ Check if config is changed @@ -255,25 +237,29 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]): if expanded_url: for index in range(len(expanded_url)): tweet = lmap( - lambda x: expanded_url[index] if x == url[index] else x, + lambda x: expanded_url[index] + if x == url[index] + else x, tweet) # Highlight RT tweet = lmap( - lambda x: color_func( - c['TWEET']['rt'])(x) if x == 'RT' else x, + lambda x: color_func(c['TWEET']['rt'])(x) + if x == 'RT' + else x, tweet) # Highlight screen_name tweet = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, tweet) # Highlight link tweet = lmap( - lambda x: color_func( - c['TWEET']['link'])(x) if x[ - 0:4] == 'http' else x, + lambda x: color_func(c['TWEET']['link'])(x) + if x[0:4] == 'http' + else x, tweet) # Highlight hashtag tweet = lmap( - lambda x: color_func( - c['TWEET']['hashtag'])(x) if x.startswith('#') else x, + lambda x: color_func(c['TWEET']['hashtag'])(x) + if x.startswith('#') + else x, tweet) # Highlight keyword tweet = ' '.join(tweet) @@ -294,10 +280,8 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]): formater = tweet.join(formater.split("#tweet")) # Change clock word word = [w for w in formater.split() if '#clock' in w][0] - delimiter = color_func( - c['TWEET']['clock'])( - clock.join( - word.split('#clock'))) + delimiter = color_func(c['TWEET']['clock'])( + clock.join(word.split('#clock'))) formater = delimiter.join(formater.split(word)) # Change id word word = [w for w in formater.split() if '#id' in w][0] @@ -378,10 +362,8 @@ def print_message(m, check_semaphore=False): formater = text.join(formater.split("#message")) # Change clock word word = [w for w in formater.split() if '#clock' in w][0] - delimiter = color_func( - c['MESSAGE']['clock'])( - clock.join( - word.split('#clock'))) + delimiter = color_func(c['MESSAGE']['clock'])( + clock.join(word.split('#clock'))) formater = delimiter.join(formater.split(word)) # Change id word word = [w for w in formater.split() if '#id' in w][0] @@ -534,5 +516,25 @@ def print_list(group): printNicely('') +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 = lmap( + lambda x: color_func(c['CAL']['today'])(x) + if x == today + else color_func(c['CAL']['days'])(x), + ary) + printNicely(' '.join(ary)) + + # Start the color cycle start_cycle() diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index a9ee2ba..c0ca8fe 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -1696,7 +1696,7 @@ def stream(domain, args, name='Rainbow Stream'): ig=args.ignore, ) elif tweet.get('direct_message'): - print_message(tweet['direct_message'],check_semaphore=True) + print_message(tweet['direct_message'], check_semaphore=True) except TwitterHTTPError: printNicely('') printNicely( diff --git a/setup.py b/setup.py index f1b0a33..eb7c58f 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ from setuptools import setup, find_packages -import os, os.path, sys +import os +import os.path +import sys # Bumped version -version = '0.5.6' +version = '0.5.7' # Require install_requires = [ @@ -14,7 +16,7 @@ install_requires = [ "Pillow", ] -# Python 3 doesn't hava pysqlite +# Python 3 doesn't have pysqlite if sys.version[0] == "2": install_requires += ["pysqlite"] -- 2.25.1