support quote format
[rainbowstream.git] / rainbowstream / draw.py
index d9afe06c3ec2ed0366e209761dbb109f35aa53de..248d1a92f2b9112ca09bc3df8cc9504202c39fbd 100644 (file)
@@ -165,6 +165,8 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
     name = t['user']['name']
     created_at = t['created_at']
     favorited = t['favorited']
+    retweet_count = t['retweet_count']
+    favorite_count = t['favorite_count']
     date = parser.parse(created_at)
     date = date - datetime.timedelta(seconds=time.timezone)
     clock_format = '%Y/%m/%d %H:%M:%S'
@@ -207,6 +209,8 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
 
     # Filter and ignore
     screen_name = '@' + screen_name
+    fil = list(set((fil or []) + c['ONLY_LIST']))
+    ig = list(set((ig or []) + c['IGNORE_LIST']))
     if fil and screen_name not in fil:
         return
     if ig and screen_name in ig:
@@ -231,7 +235,7 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
     tweet = text.split()
     # Replace url
     if expanded_url:
-        for index in range(len(expanded_url)):
+        for index in xrange(len(expanded_url)):
             tweet = lmap(
                 lambda x: expanded_url[index]
                 if x == url[index]
@@ -268,12 +272,13 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
             tweet = delimiter.join(ary)
 
     # Load config formater
+    formater = ''
     try:
         formater = c['FORMAT']['TWEET']['DISPLAY']
-        formater = name.join(formater.split("#name"))
-        formater = nick.join(formater.split("#nick"))
-        formater = fav.join(formater.split("#fav"))
-        formater = tweet.join(formater.split("#tweet"))
+        formater = name.join(formater.split('#name'))
+        formater = nick.join(formater.split('#nick'))
+        formater = fav.join(formater.split('#fav'))
+        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'])(
@@ -283,9 +288,18 @@ def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
         word = [w for w in formater.split() if '#id' in w][0]
         delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id')))
         formater = delimiter.join(formater.split(word))
+        # Change retweet count word
+        word = [w for w in formater.split() if '#rt_count' in w][0]
+        delimiter = color_func(c['TWEET']['retweet_count'])(
+            str(retweet_count).join(word.split('#rt_count')))
+        formater = delimiter.join(formater.split(word))
+        # Change favorites count word
+        word = [w for w in formater.split() if '#fa_count' in w][0]
+        delimiter = color_func(c['TWEET']['favorite_count'])(
+            str(favorite_count).join(word.split('#fa_count')))
+        formater = delimiter.join(formater.split(word))
     except:
-        printNicely(red('Wrong format in config.'))
-        return
+        pass
 
     # Draw
     printNicely(formater)