import requests
import datetime
import time
+import re
from twitter.util import printNicely
from functools import wraps
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
"""
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(
printNicely(line4)
printNicely('')
+
+
+# Start the color cycle
+start_cycle()
\ No newline at end of file
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():
# 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'] + ']: ')