re saerch keyword without hashtag
authorOrakaro <nhatminh_179@hotmail.com>
Thu, 17 Jul 2014 13:32:13 +0000 (22:32 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Thu, 17 Jul 2014 13:32:13 +0000 (22:32 +0900)
rainbowstream/draw.py
rainbowstream/rainbow.py
setup.py

index 0abdede..d3e18dc 100644 (file)
@@ -3,6 +3,7 @@ import itertools
 import requests
 import datetime
 import time
+import re
 
 from twitter.util import printNicely
 from functools import wraps
@@ -28,11 +29,9 @@ def init_cycle():
                       else term_color(int(i))
                       for i in c['CYCLE_COLOR']]
     return itertools.cycle(colors_shuffle)
-g['cyc'] = init_cycle()
-g['cache'] = {}
 
 
-def reset_cycle():
+def start_cycle():
     """
     Notify from rainbow
     """
@@ -219,16 +218,16 @@ def draw(t, iot=False, keyword=None, fil=[], ig=[]):
             c['TWEET']['link'])(x) if x[
             0:4] == 'http' else x,
         tweet)
-    # Highlight search keyword
-    if keyword:
-        tweet = lmap(
-            lambda x: color_func(c['TWEET']['keyword'])(x) if
-            ''.join(c for c in x if c.isalnum()).lower() == keyword.lower()
-            else x,
-            tweet
-        )
-    # Recreate tweet
+
+    # Highlight keyword
     tweet = ' '.join(tweet)
+    if keyword:
+        roj = re.search(keyword,tweet,re.IGNORECASE)
+        if roj:
+            occur = roj.group()
+            ary = tweet.split(occur)
+            delimeter = color_func(c['TWEET']['keyword'])(occur)
+            tweet = delimeter.join(ary)
 
     # Draw rainbow
     line1 = u"{u:>{uw}}:".format(
@@ -445,3 +444,7 @@ def print_list(group):
         printNicely(line4)
 
     printNicely('')
+
+
+# Start the color cycle
+start_cycle()
\ No newline at end of file
index 9444087..233f441 100644 (file)
@@ -438,19 +438,17 @@ def search():
     Search
     """
     t = Twitter(auth=authen())
-    if g['stuff'].startswith('#'):
-        rel = t.search.tweets(q=g['stuff'])['statuses']
-        if rel:
-            printNicely('Newest tweets:')
-            for i in reversed(xrange(c['SEARCH_MAX_RECORD'])):
-                draw(t=rel[i],
-                     iot=g['iot'],
-                     keyword=g['stuff'].strip()[1:])
-            printNicely('')
-        else:
-            printNicely(magenta('I\'m afraid there is no result'))
+    g['stuff'] = g['stuff'].strip()
+    rel = t.search.tweets(q=g['stuff'])['statuses']
+    if rel:
+        printNicely('Newest tweets:')
+        for i in reversed(xrange(c['SEARCH_MAX_RECORD'])):
+            draw(t=rel[i],
+                 iot=g['iot'],
+                 keyword=g['stuff'])
+        printNicely('')
     else:
-        printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
+        printNicely(magenta('I\'m afraid there is no result'))
 
 
 def message():
@@ -1129,7 +1127,7 @@ def theme():
             # Update db and reset colors
             db.theme_update(g['stuff'])
             c['THEME'] = g['stuff']
-            reset_cycle()
+            start_cycle()
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')
index 501457c..95fa835 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
 import os, sys
 
 # Bumped version
-version = '0.3.9'
+version = '0.3.10'
 
 # Require
 install_requires = [