Colorful user's timeline stream
"""
from multiprocessing import Process
-from dateutil import parser
import os
import os.path
import signal
import argparse
import time
-import datetime
import requests
from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
'unblock',
'report',
'cal',
+ 'theme',
'h',
'c',
'q'
g['original_name'] = name[1:]
g['decorated_name'] = grey('[') + grey(name) + grey(']: ')
+ files = os.listdir('rainbowstream/colorset')
+ themes = [f.split('.')[0] for f in files if f.split('.')[-1]=='json']
+ g['themes'] = themes
+
def switch():
"""
args.filter = filter(None, only.split(','))
args.ignore = filter(None, ignore.split(','))
elif g['stuff'].split()[-1] == '-d':
- args.filter = ONLY_LIST
- args.ignore = IGNORE_LIST
+ args.filter = c['ONLY_LIST']
+ args.ignore = c['IGNORE_LIST']
except:
printNicely(red('Sorry, wrong format.'))
return
p = Process(
target=stream,
args=(
- PUBLIC_DOMAIN,
+ c['PUBLIC_DOMAIN'],
args))
p.start()
g['stream_pid'] = p.pid
p = Process(
target=stream,
args=(
- USER_DOMAIN,
+ c['USER_DOMAIN'],
args,
g['original_name']))
p.start()
Home
"""
t = Twitter(auth=authen())
- num = HOME_TWEET_NUM
+ num = c['HOME_TWEET_NUM']
if g['stuff'].isdigit():
num = int(g['stuff'])
for tweet in reversed(t.statuses.home_timeline(count=num)):
try:
num = int(g['stuff'].split()[1])
except:
- num = HOME_TWEET_NUM
+ num = c['HOME_TWEET_NUM']
for tweet in reversed(t.statuses.user_timeline(count=num, screen_name=user[1:])):
draw(t=tweet, iot=g['iot'])
printNicely('')
Mentions timeline
"""
t = Twitter(auth=authen())
- num = HOME_TWEET_NUM
+ num = c['HOME_TWEET_NUM']
if g['stuff'].isdigit():
num = int(g['stuff'])
for tweet in reversed(t.statuses.mentions_timeline(count=num)):
try:
num = int(g['stuff'].split()[1])
except:
- num = RETWEETS_SHOW_NUM
+ num = c['RETWEETS_SHOW_NUM']
# Get result and display
rt_ary = t.statuses.retweets(id=tid, count=num)
if not rt_ary:
rel = t.search.tweets(q=g['stuff'])['statuses']
if rel:
printNicely('Newest tweets:')
- for i in reversed(xrange(SEARCH_MAX_RECORD)):
+ for i in reversed(xrange(c['SEARCH_MAX_RECORD'])):
draw(t=rel[i],
iot=g['iot'],
keyword=g['stuff'].strip()[1:])
Inbox direct messages
"""
t = Twitter(auth=authen())
- num = MESSAGES_DISPLAY
+ num = c['MESSAGES_DISPLAY']
rel = []
if g['stuff'].isdigit():
num = g['stuff']
Sent direct messages
"""
t = Twitter(auth=authen())
- num = MESSAGES_DISPLAY
+ num = c['MESSAGES_DISPLAY']
rel = []
if g['stuff'].isdigit():
num = int(g['stuff'])
"""
t = Twitter(auth=authen())
# Init cursor
- d = {'fl': 'followers', 'fr': 'friends'}
next_cursor = -1
rel = {}
# Cursor loop
printNicely(' '.join(ary))
+def theme():
+ """
+ List and change theme
+ """
+ if not g['stuff']:
+ # List themes
+ for theme in g['themes']:
+ line = ' '*2 + magenta('* ' + theme)
+ printNicely(line)
+ else:
+ # Change theme
+ try :
+ new_config = 'rainbowstream/colorset/' + g['stuff'] + '.json'
+ new_config = load_config(new_config)
+ for nc in new_config:
+ c[nc] = new_config[nc]
+ printNicely(green('Theme changed.'))
+ except :
+ printNicely(red('Sorry, config file is broken!'))
+
+
def help():
"""
Help
' filter will decide nicks will be EXCLUDE.\n'
usage += s * 2 + green('switch mine -d') + \
' will use the config\'s ONLY_LIST and IGNORE_LIST.\n'
- usage += s * 3 + '(see ' + grey('rainbowstream/config.py') + ').\n'
# Smart shell
usage += '\n'
# Screening
usage += '\n'
usage += s + grey(u'\u266A' + ' Screening \n')
+ usage += s * 2 + green('theme') + ' will list available theme.' + \
+ green('theme monokai') + ' will apply '+ yellow('monokai') + \
+ ' theme immediately.\n'
usage += s * 2 + green('h') + ' will show this help again.\n'
usage += s * 2 + green('c') + ' will clear the screen.\n'
usage += s * 2 + green('q') + ' will quit.\n'
unblock,
report,
cal,
+ theme,
help,
clear,
quit
['@'], # unblock
['@'], # report
[], # cal
+ g['themes'], # theme
[], # help
[], # clear
[], # quit
# The Logo
art_dict = {
- USER_DOMAIN: name,
- PUBLIC_DOMAIN: args.track_keywords,
- SITE_DOMAIN: 'Site Stream',
+ c['USER_DOMAIN']: name,
+ c['PUBLIC_DOMAIN']: args.track_keywords,
+ c['SITE_DOMAIN']: 'Site Stream',
}
ascii_art(art_dict[domain])
domain=domain,
**stream_args)
- if domain == USER_DOMAIN:
+ if domain == c['USER_DOMAIN']:
tweet_iter = stream.user(**query_args)
- elif domain == SITE_DOMAIN:
+ elif domain == c['SITE_DOMAIN']:
tweet_iter = stream.site(**query_args)
else:
if args.track_keywords:
# Spawn stream process
args = parse_arguments()
get_decorated_name()
- p = Process(target=stream, args=(USER_DOMAIN, args, g['original_name']))
+ p = Process(target=stream, args=(c['USER_DOMAIN'], args, g['original_name']))
p.start()
# Start listen process