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 0abdedee7657245f2380c1f020de20a0a4f2cee8..d3e18dc97860a11129ebf1d5aa6da4ca39d3daab 100644 (file)
@@ -3,6 +3,7 @@ import itertools
 import requests
 import datetime
 import time
 import requests
 import datetime
 import time
+import re
 
 from twitter.util import printNicely
 from functools import wraps
 
 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)
                       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
     """
     """
     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)
             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)
     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(
 
     # Draw rainbow
     line1 = u"{u:>{uw}}:".format(
@@ -445,3 +444,7 @@ def print_list(group):
         printNicely(line4)
 
     printNicely('')
         printNicely(line4)
 
     printNicely('')
+
+
+# Start the color cycle
+start_cycle()
\ No newline at end of file
index 94440877f32f09b14add6703ad3dad1a3344159b..233f441df1b0df9c5667792d06e689ee17a03668 100644 (file)
@@ -438,19 +438,17 @@ def search():
     Search
     """
     t = Twitter(auth=authen())
     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:
     else:
-        printNicely(red('A keyword should be a hashtag (like \'#AKB48\')'))
+        printNicely(magenta('I\'m afraid there is no result'))
 
 
 def message():
 
 
 def message():
@@ -1129,7 +1127,7 @@ def theme():
             # Update db and reset colors
             db.theme_update(g['stuff'])
             c['THEME'] = g['stuff']
             # 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'] + ']: ')
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')
index 501457c33aa1c643839cd60281b9fb49071d371c..95fa835eb8d2b5f9bc158a0d86f05787d83d9d06 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
 import os, sys
 
 # Bumped version
 import os, sys
 
 # Bumped version
-version = '0.3.9'
+version = '0.3.10'
 
 # Require
 install_requires = [
 
 # Require
 install_requires = [