refactoring some code
authorvunhat_minh <vunhat_minh@dwango.co.jp>
Tue, 29 Jul 2014 09:56:13 +0000 (18:56 +0900)
committervunhat_minh <vunhat_minh@dwango.co.jp>
Tue, 29 Jul 2014 09:56:13 +0000 (18:56 +0900)
docs/conf.py
rainbowstream/db.py
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

index e5b64fe487273d33e2a3ce064374a33784393169..a94a09497130df9f01c9c729553ab7712d05eeb1 100644 (file)
@@ -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.
index 01b91fb163fbd7e5933da975d46e878610ae87d1..192448fd44a941e8bb3034ee613b10da19e0be88 100644 (file)
@@ -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
index 589d5f3a8ccb8944bb6b264b6ca83e996de06ab4..78c3a26ae10d1a6101e6c7243687b6f56bf46983 100644 (file)
@@ -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()
index a9ee2bab32b421d1d5dcee1dcbcdff27ade09dfe..c0ca8febd2d934b51e9128c801c47f7454af49e1 100644 (file)
@@ -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(
index f1b0a3307f928c6d720828a003e2dcb79e464afe..eb7c58f014200d46c24198c411dbb12100295201 100644 (file)
--- 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"]