return globals()[func_name]
-def draw(t, keyword=None, humanize=True, check_semaphore=False, fil=[], ig=[]):
+def draw(t, keyword=None, humanize=True, fil=[], ig=[]):
"""
Draw the rainbow
"""
-
- # Check the semaphore pause and lock (stream process only)
- if check_semaphore:
- if c['pause']:
- return
- while c['lock']:
- time.sleep(0.5)
-
# Check config
check_config()
printNicely(red('Sorry, image link is broken'))
-def print_message(m, check_semaphore=False):
+def print_message(m):
"""
Print direct message
"""
-
- # Check the semaphore pause and lock (stream process only)
- if check_semaphore:
- if c['pause']:
- return
- while c['lock']:
- time.sleep(0.5)
-
# Retrieve message
sender_screen_name = '@' + m['sender_screen_name']
sender_name = m['sender']['name']
except:
pass
# Highlight like a tweet
- formater = formater.split()
- formater = lmap(
+ notice = formater.split()
+ notice = lmap(
lambda x: light_green(x)
if x == '#comment'
else x,
- formater)
- formater = lmap(
+ notice)
+ notice = lmap(
lambda x: color_func(c['TWEET']['rt'])(x)
if x == 'RT'
else x,
- formater)
- formater = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, formater)
- formater = lmap(
+ notice)
+ notice = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, notice)
+ notice = lmap(
lambda x: color_func(c['TWEET']['link'])(x)
if x[0:4] == 'http'
else x,
- formater)
- formater = lmap(
+ notice)
+ notice = lmap(
lambda x: color_func(c['TWEET']['hashtag'])(x)
if x.startswith('#')
else x,
- formater)
- formater = ' '.join(formater)
+ notice)
+ notice = ' '.join(notice)
# Notice
- notice = light_magenta('Quoting: "') + formater + light_magenta('"')
+ notice = light_magenta('Quoting: "') + notice + light_magenta('"')
printNicely(notice)
return formater
files = os.listdir(os.path.dirname(__file__) + '/colorset')
themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
g['themes'] = themes
+ g['pause'] = False
# Startup cmd
g['cmd'] = ''
# Semaphore init
c['lock'] = False
- c['pause'] = False
# Init tweet dict and message dict
c['tweet_dict'] = []
c['message_dict'] = []
"""
Pause stream display
"""
- c['pause'] = True
+ g['pause'] = True
printNicely(green('Stream is paused'))
"""
Replay stream
"""
- c['pause'] = False
+ g['pause'] = False
printNicely(green('Stream is running back now'))
elif tweet is Hangup:
printNicely("-- Hangup --")
elif tweet.get('text'):
+ # Check the semaphore pause and lock (stream process only)
+ if g['pause']:
+ continue
+ while c['lock']:
+ time.sleep(0.5)
+ # Draw the tweet
draw(
t=tweet,
keyword=args.track_keywords,
humanize=False,
- check_semaphore=True,
fil=args.filter,
ig=args.ignore,
)
sys.stdout.write(g['decorated_name'](c['PREFIX']))
sys.stdout.flush()
elif tweet.get('direct_message'):
- print_message(tweet['direct_message'], check_semaphore=True)
+ # Check the semaphore pause and lock (stream process only)
+ if g['pause']:
+ continue
+ while c['lock']:
+ time.sleep(0.5)
+ print_message(tweet['direct_message'])
except TwitterHTTPError:
printNicely('')
printNicely(