name = credential['name']
if not get_config('PREFIX'):
set_config('PREFIX', screen_name)
- g['original_name'] = screen_name[1:]
+ g['PREFIX'] = u2str(c['PREFIX'])
+ c['original_name'] = g['original_name'] = screen_name[1:]
g['full_name'] = name
g['decorated_name'] = lambda x: color_func(
c['DECORATED_NAME'])('[' + x + ']: ')
Search
"""
t = Twitter(auth=authen())
- g['stuff'] = g['stuff'].strip()
- rel = t.search.tweets(q=g['stuff'])['statuses']
+ # Setup query
+ query = g['stuff'].strip()
+ type = c['SEARCH_TYPE']
+ if type not in ['mixed', 'recent', 'popular']:
+ type = 'mixed'
+ max_record = c['SEARCH_MAX_RECORD']
+ count = min(max_record, 100)
+ # Perform search
+ rel = t.search.tweets(
+ q=query,
+ type=type,
+ count=count
+ )['statuses']
+ # Return results
if rel:
printNicely('Newest tweets:')
- for i in reversed(xrange(c['SEARCH_MAX_RECORD'])):
- draw(t=rel[i],
- keyword=g['stuff'])
+ for i in reversed(xrange(count)):
+ draw(t=rel[i], keyword=query)
printNicely('')
else:
printNicely(magenta('I\'m afraid there is no result'))
return
tid = c['tweet_dict'][int(g['stuff'])]
tweet = t.statuses.show(id=tid)
- link_ary = [
- u for u in tweet['text'].split() if u.startswith('http://')]
+ link_prefix = ('http://', 'https://')
+ link_ary = [u for u in tweet['text'].split()
+ if u.startswith(link_prefix)]
if not link_ary:
printNicely(light_magenta('No url here @.@!'))
return
d = {}
uniq_inbox = list(set(
- [(m['sender_screen_name'],m['sender']['name']) for m in inbox]
+ [(m['sender_screen_name'], m['sender']['name']) for m in inbox]
))
- uniq_sent= list(set(
- [(m['recipient_screen_name'],m['recipient']['name']) for m in sent]
+ uniq_sent = list(set(
+ [(m['recipient_screen_name'], m['recipient']['name']) for m in sent]
))
for partner in uniq_inbox:
inbox_ary = [m for m in inbox if m['sender_screen_name'] == partner[0]]
- sent_ary = [m for m in sent if m['recipient_screen_name'] == partner[0]]
+ sent_ary = [
+ m for m in sent if m['recipient_screen_name'] == partner[0]]
d[partner] = inbox_ary + sent_ary
for partner in uniq_sent:
if partner not in d:
- d[partner] = [m for m in sent if m['recipient_screen_name'] == partner[0]]
+ d[partner] = [
+ m for m in sent if m['recipient_screen_name'] == partner[0]]
g['message_threads'] = print_threads(d)
"""
try:
thread_id = int(g['stuff'])
- print_thread(g['message_threads'][thread_id],g['original_name'],g['full_name'])
- except Exception as e:
- print(e)
- import traceback
- print(traceback.format_exc())
+ print_thread(
+ g['message_threads'][thread_id],
+ g['original_name'],
+ g['full_name'])
+ except Exception:
printNicely(red('No such thread.'))
Send a direct message
"""
t = Twitter(auth=authen())
- user = g['stuff'].split()[0]
- if user[0].startswith('@'):
- try:
- content = g['stuff'].split()[1]
- except:
- printNicely(red('Sorry I can\'t understand.'))
- t.direct_messages.new(
- screen_name=user[1:],
- text=content
- )
- printNicely(green('Message sent.'))
- else:
- printNicely(red('A name should begin with a \'@\''))
+ try:
+ user = g['stuff'].split()[0]
+ if user[0].startswith('@'):
+ content = ' '.join(g['stuff'].split()[1:])
+ t.direct_messages.new(
+ screen_name=user[1:],
+ text=content
+ )
+ printNicely(green('Message sent.'))
+ else:
+ printNicely(red('A name should begin with a \'@\''))
+ except:
+ printNicely(red('Sorry I can\'t understand.'))
def trash():
usage += s + grey(u'\u266A' + ' Direct messages \n')
usage += s * 2 + light_green('inbox') + ' will show inbox messages. ' + \
light_green('inbox 7') + ' will show newest 7 messages.\n'
- usage += s * 2 + light_green('sent') + ' will show sent messages. ' + \
- light_green('sent 7') + ' will show newest 7 messages.\n'
+ usage += s * 2 + light_green('thread 2') + ' will show full thread with ' + \
+ light_yellow('[thread_id=2]') + '.\n'
usage += s * 2 + light_green('mes @dtvd88 hi') + ' will send a "hi" messege to ' + \
magenta('@dtvd88') + '.\n'
usage += s * 2 + light_green('trash 5') + ' will remove message with ' + \
[''], # open url
['fl', 'fr'], # list
[], # inbox
- [i for i in g['message_threads']], #sent
+ [i for i in g['message_threads']], # sent
[], # trash
['@'], # whois
['@'], # follow
try:
# raw_input
if g['prefix']:
- line = raw_input(g['decorated_name'](c['PREFIX']))
+ line = raw_input(g['decorated_name'](g['PREFIX']))
else:
line = raw_input()
# Save cmd to compare with readline buffer
light_green("h stream") + \
light_magenta(" for more details.")
printNicely(guide)
- sys.stdout.write(g['decorated_name'](c['PREFIX']))
+ sys.stdout.write(g['decorated_name'](g['PREFIX']))
sys.stdout.flush()
StreamLock.release()
break
# the 1st character of that word
if current_buffer and g['cmd'] != current_buffer:
sys.stdout.write(
- g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
+ g['decorated_name'](g['PREFIX']) + str2u(current_buffer))
sys.stdout.flush()
elif not c['HIDE_PROMPT']:
- sys.stdout.write(g['decorated_name'](c['PREFIX']))
+ sys.stdout.write(g['decorated_name'](g['PREFIX']))
sys.stdout.flush()
elif tweet.get('direct_message'):
# Check the semaphore pause and lock (stream process only)