From 59262e95e7c51d9d39d8a65bbd5ca05231ad1e40 Mon Sep 17 00:00:00 2001 From: Orakaro Date: Thu, 17 Jul 2014 22:32:13 +0900 Subject: [PATCH] re saerch keyword without hashtag --- rainbowstream/draw.py | 27 +++++++++++++++------------ rainbowstream/rainbow.py | 24 +++++++++++------------- setup.py | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index 0abdede..d3e18dc 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -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 diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index 9444087..233f441 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -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'] + ']: ') diff --git a/setup.py b/setup.py index 501457c..95fa835 100644 --- 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 = [ -- 2.25.1