X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Frainbow.py;h=84b89ffcf6a8f3988bef4c0c72257dbf98641297;hp=f489c3f67a4a3b097baf3e4f2f4ebd1ebe21c3c5;hb=b8dda7041add749421f08c022e04023b6a939a29;hpb=f405a7d0c54ab0657af3bab77f6eb28a98f8921e diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index f489c3f..84b89ff 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -19,7 +19,7 @@ from .config import * g = {} -def draw(t): +def draw(t,keyword=None): """ Draw the rainbow """ @@ -35,9 +35,14 @@ def draw(t): user = cycle_color(name) + grey(' ' + '@' + screen_name + ' ') clock = grey('[' + time + ']') tweet = text.split() + # Highlight RT tweet = map(lambda x: grey(x) if x == 'RT' else x, tweet) + # Highlight screen_name tweet = map(lambda x: cycle_color(x) if x[0] == '@' else x, tweet) + # Highlight link tweet = map(lambda x: cyan(x) if x[0:7] == 'http://' else x, tweet) + # Highlight search keyword + tweet = map(lambda x: on_yellow(x) if ''.join(c for c in x if c.isalnum()).lower() == keyword.lower() else x, tweet) tweet = ' '.join(tweet) # Draw rainbow @@ -133,9 +138,9 @@ def search(): t = Twitter(auth=authen()) rel = t.search.tweets(q='#' + g['stuff'])['statuses'] printNicely(grey('**************************************************************************************\n')) - print('Newest ',SEARCH_MAX_RECORD, ' tweet: \n') + print('Newest',SEARCH_MAX_RECORD, 'tweet: \n') for i in xrange(5): - draw(t=rel[i]) + draw(t=rel[i],keyword=g['stuff'].strip()) printNicely(grey('**************************************************************************************\n')) @@ -147,8 +152,9 @@ def help(): Hi boss! I'm ready to serve you right now! ---------------------------------------------------- "!" at the beginning will start to tweet immediately - "/" at the beginning will search for 5 lastest twwet - "?" will print this help once again + "/" at the beginning will search for 5 newest tweet + "?" or "h" will print this help once again + "c" will clear the terminal "q" will exit ---------------------------------------------------- Hvae fun and hang tight! @@ -165,6 +171,13 @@ def quit(): sys.exit() +def clear(): + """ + Exit all + """ + os.system('clear') + + def process(line): """ Process switch by start of line @@ -173,6 +186,8 @@ def process(line): '!' : tweet, '/' : search, '?' : help, + 'h' : help, + 'c' : clear, 'q' : quit, }.get(line[0],lambda: sys.stdout.write(g['decorated_name'])) @@ -196,8 +211,6 @@ def stream(): # The Logo ascii_art() - print("Tip: Press ENTER and type a '?' to see what command mode can do for you") - print('\n') # These arguments are optional: stream_args = dict( timeout=args.timeout,