+def show_lists(t):
+ """
+ List list
+ """
+ rel = t.lists.list(screen_name=g['original_name'])
+ if rel:
+ print_list(rel)
+ else:
+ printNicely(light_magenta('You belong to no lists :)'))
+
+
+def list_home(t):
+ """
+ List home
+ """
+ owner, slug = get_slug()
+ res = t.lists.statuses(
+ slug=slug,
+ owner_screen_name=owner,
+ count=c['LIST_MAX'],
+ include_entities=False)
+ for tweet in res:
+ draw(t=tweet)
+ printNicely('')
+
+
+def list_members(t):
+ """
+ List members
+ """
+ owner, slug = get_slug()
+ # Get members
+ rel = {}
+ next_cursor = -1
+ while next_cursor != 0:
+ m = t.lists.members(
+ slug=slug,
+ owner_screen_name=owner,
+ cursor=next_cursor,
+ include_entities=False)
+ for u in m['users']:
+ rel[u['name']] = '@' + u['screen_name']
+ next_cursor = m['next_cursor']
+ printNicely('All: ' + str(len(rel)) + ' members.')
+ for name in rel:
+ user = ' ' + cycle_color(name)
+ user += color_func(c['TWEET']['nick'])(' ' + rel[name] + ' ')
+ printNicely(user)
+
+
+def list_subscribers(t):
+ """
+ List subscribers
+ """
+ owner, slug = get_slug()
+ # Get subscribers
+ rel = {}
+ next_cursor = -1
+ while next_cursor != 0:
+ m = t.lists.subscribers(
+ slug=slug,
+ owner_screen_name=owner,
+ cursor=next_cursor,
+ include_entities=False)
+ for u in m['users']:
+ rel[u['name']] = '@' + u['screen_name']
+ next_cursor = m['next_cursor']
+ printNicely('All: ' + str(len(rel)) + ' subscribers.')
+ for name in rel:
+ user = ' ' + cycle_color(name)
+ user += color_func(c['TWEET']['nick'])(' ' + rel[name] + ' ')
+ printNicely(user)
+
+
+def list_add(t):
+ """
+ Add specific user to a list
+ """
+ owner, slug = get_slug()
+ # Add
+ user_name = raw_input(light_magenta('Give me name of the newbie: '))
+ if user_name.startswith('@'):
+ user_name = user_name[1:]
+ try:
+ t.lists.members.create(
+ slug=slug,
+ owner_screen_name=owner,
+ screen_name=user_name)
+ printNicely(light_green('Added.'))
+ except:
+ printNicely(light_magenta('I\'m sorry we can not add him/her.'))
+
+
+def list_remove(t):
+ """
+ Remove specific user from a list
+ """
+ owner, slug = get_slug()
+ # Remove
+ user_name = raw_input(light_magenta('Give me name of the unlucky one: '))
+ if user_name.startswith('@'):
+ user_name = user_name[1:]
+ try:
+ t.lists.members.destroy(
+ slug=slug,
+ owner_screen_name=owner,
+ screen_name=user_name)
+ printNicely(light_green('Gone.'))
+ except:
+ printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
+
+
+def list_subscribe(t):
+ """
+ Subscribe to a list
+ """
+ owner, slug = get_slug()
+ # Subscribe
+ try:
+ t.lists.subscribers.create(
+ slug=slug,
+ owner_screen_name=owner)
+ printNicely(light_green('Done.'))
+ except:
+ printNicely(
+ light_magenta('I\'m sorry you can not subscribe to this list.'))
+
+
+def list_unsubscribe(t):
+ """
+ Unsubscribe a list
+ """
+ owner, slug = get_slug()
+ # Subscribe
+ try:
+ t.lists.subscribers.destroy(
+ slug=slug,
+ owner_screen_name=owner)
+ printNicely(light_green('Done.'))
+ except:
+ printNicely(
+ light_magenta('I\'m sorry you can not unsubscribe to this list.'))
+
+
+def list_own(t):
+ """
+ List own
+ """
+ rel = []
+ next_cursor = -1
+ while next_cursor != 0:
+ res = t.lists.ownerships(
+ screen_name=g['original_name'],
+ cursor=next_cursor)
+ rel += res['lists']
+ next_cursor = res['next_cursor']
+ if rel:
+ print_list(rel)
+ else:
+ printNicely(light_magenta('You own no lists :)'))
+
+
+def list_new(t):
+ """
+ Create a new list
+ """
+ name = raw_input(light_magenta('New list\'s name: '))
+ mode = raw_input(light_magenta('New list\'s mode (public/private): '))
+ description = raw_input(light_magenta('New list\'s description: '))
+ try:
+ t.lists.create(
+ name=name,
+ mode=mode,
+ description=description)
+ printNicely(light_green(name + ' list is created.'))
+ except:
+ printNicely(red('Oops something is wrong with Twitter :('))
+
+
+def list_update(t):
+ """
+ Update a list
+ """
+ slug = raw_input(light_magenta('Your list that you want to update: '))
+ name = raw_input(light_magenta('Update name (leave blank to unchange): '))
+ mode = raw_input(light_magenta('Update mode (public/private): '))
+ description = raw_input(light_magenta('Update description: '))
+ try:
+ if name:
+ t.lists.update(
+ slug='-'.join(slug.split()),
+ owner_screen_name=g['original_name'],
+ name=name,
+ mode=mode,
+ description=description)
+ else:
+ t.lists.update(
+ slug=slug,
+ owner_screen_name=g['original_name'],
+ mode=mode,
+ description=description)
+ printNicely(light_green(slug + ' list is updated.'))
+ except:
+ printNicely(red('Oops something is wrong with Twitter :('))
+
+
+def list_delete(t):
+ """
+ Delete a list
+ """
+ slug = raw_input(light_magenta('Your list that you want to update: '))
+ try:
+ t.lists.destroy(
+ slug='-'.join(slug.split()),
+ owner_screen_name=g['original_name'])
+ printNicely(light_green(slug + ' list is deleted.'))
+ except:
+ printNicely(red('Oops something is wrong with Twitter :('))
+
+
+def list():
+ """
+ Twitter's list
+ """
+ t = Twitter(auth=authen())
+ # List all lists or base on action
+ try:
+ g['list_action'] = g['stuff'].split()[0]
+ except:
+ show_lists(t)
+ return
+ # Sub-function
+ action_ary = {
+ 'home': list_home,
+ 'all_mem': list_members,
+ 'all_sub': list_subscribers,
+ 'add': list_add,
+ 'rm': list_remove,
+ 'sub': list_subscribe,
+ 'unsub': list_unsubscribe,
+ 'own': list_own,
+ 'new': list_new,
+ 'update': list_update,
+ 'del': list_delete,
+ }
+ try:
+ return action_ary[g['list_action']](t)
+ except:
+ printNicely(red('Please try again.'))
+
+
+def cal():
+ """
+ Unix's command `cal`
+ """
+ # Format
+ rel = os.popen('cal').read().split('\n')
+ month = rel.pop(0)
+ date = rel.pop(0)
+ show_calendar(month, date, rel)
+
+
+def config():
+ """
+ Browse and change config
+ """
+ all_config = get_all_config()
+ g['stuff'] = g['stuff'].strip()
+ # List all config
+ if not g['stuff']:
+ for k in all_config:
+ line = ' ' * 2 + \
+ light_green(k) + ': ' + light_yellow(str(all_config[k]))
+ printNicely(line)
+ guide = 'Detailed explanation can be found at ' + \
+ color_func(c['TWEET']['link'])(
+ 'http://rainbowstream.readthedocs.org/en/latest/#config-explanation')
+ printNicely(guide)
+ # Print specific config
+ elif len(g['stuff'].split()) == 1:
+ if g['stuff'] in all_config:
+ k = g['stuff']
+ line = ' ' * 2 + \
+ light_green(k) + ': ' + light_yellow(str(all_config[k]))
+ printNicely(line)
+ else:
+ printNicely(red('No config key like this.'))
+ # Print specific config's default value
+ elif len(g['stuff'].split()) == 2 and g['stuff'].split()[-1] == 'default':
+ key = g['stuff'].split()[0]
+ value = get_default_config(key)
+ line = ' ' * 2 + light_green(key) + ': ' + light_magenta(value)
+ printNicely(line)
+ # Set specific config
+ elif len(g['stuff'].split()) == 3 and g['stuff'].split()[1] == '=':
+ key = g['stuff'].split()[0]
+ value = g['stuff'].split()[-1]
+ try:
+ set_config(key, value)
+ printNicely(light_green('Updated successfully.'))
+ except:
+ printNicely(light_magenta('Not valid value.'))
+ return
+ reload_config()
+ else:
+ printNicely(light_magenta('Sorry I can\'s understand.'))
+
+
+def theme():
+ """
+ List and change theme
+ """
+ if not g['stuff']:
+ # List themes
+ for theme in g['themes']:
+ line = light_magenta(theme)
+ if c['THEME'] == theme:
+ line = ' ' * 2 + light_yellow('* ') + line
+ else:
+ line = ' ' * 4 + line
+ printNicely(line)
+ elif g['stuff'] == 'current_as_default':
+ # Set as default
+ set_config('THEME', c['THEME'])
+ printNicely(light_green('Okay it will be applied from next time :)'))
+ else:
+ # Change theme
+ try:
+ # Load new config
+ if g['stuff'] != 'custom':
+ new_config = os.path.dirname(
+ __file__) + '/colorset/' + g['stuff'] + '.json'
+ else:
+ new_config = os.environ.get(
+ 'HOME', os.environ.get(
+ 'USERPROFILE',
+ '')) + os.sep + '.rainbow_config.json'
+ new_config = load_config(new_config)
+ if new_config:
+ for nc in new_config:
+ c[nc] = new_config[nc]
+ # Update db and reset colors
+ db.theme_update(g['stuff'])
+ c['THEME'] = g['stuff']
+ start_cycle()
+ g['decorated_name'] = color_func(
+ c['DECORATED_NAME'])(
+ '[@' + g['original_name'] + ']: ')
+ printNicely(green('Theme changed.'))
+ except:
+ printNicely(red('No such theme exists.'))
+
+
+def help_discover():
+ """
+ Discover the world
+ """
+ s = ' ' * 2
+ # Discover the world
+ usage = '\n'