Fix blank line
[rainbowstream.git] / rainbowstream / rainbow.py
index 47b6ec3..a7007cc 100644 (file)
@@ -245,12 +245,13 @@ def init(args):
     credential = t.account.verify_credentials()
     screen_name = '@' + credential['screen_name']
     name = credential['name']
+    g['id_str'] = credential['id_str']
     c['original_name'] = g['original_name'] = screen_name[1:]
     g['listname'] = g['keyword'] = ''
     g['PREFIX'] = u2str(emojize(format_prefix()))
     g['full_name'] = name
     g['decorated_name'] = lambda x: color_func(
-        c['DECORATED_NAME'])('[' + x + ']: ')
+        c['DECORATED_NAME'])('[' + x + ']: ', rl=True)
     # Theme init
     files = os.listdir(os.path.dirname(__file__) + '/colorset')
     themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
@@ -340,7 +341,8 @@ def poll():
         g['since_id'] = result[0]['id']
     for tweet in reversed(result):
         draw(t=tweet)
-    printNicely('')
+    if result:
+        printNicely('')
 
 def home():
     """
@@ -818,22 +820,34 @@ def inbox():
         num = g['stuff']
 
     def inboxFilter(message):
-        return message['sender_screen_name'] == g['original_name']
+        return message['message_create']['sender_id'] == g['id_str']
     def sentFilter(message):
-        return message['recipient_screen_name'] == g['original_name']
+        return message['message_create']['target']['recipient_id'] == g['id_str']
+
+    def map_message(message):
+        message_create = message['message_create']
+        sender = t.users.show(id=int(message_create['sender_id']),include_entities=False)
+        recipient = t.users.show(id=int(message_create['target']['recipient_id']),include_entities=False)
+        message['sender_screen_name'] = sender['screen_name']
+        message['sender_name'] = sender['name']
+        message['recipient_screen_name'] = recipient['screen_name']
+        message['recipient_name'] = recipient['name']
+        message['text'] = message['message_create']['message_data']['text']
+        message['created_at'] = message['created_timestamp']
+        return message
 
     # Get inbox messages
-    messages = []
-    messages = messages + t.direct_messages.events.list()['events']
-    inbox = filter(inboxFilter, messages)
-    sent = filter(inboxFilter, messages)
+    messages = t.direct_messages.events.list()['events']
+    messages = list(map(map_message, messages))
+    inbox = list(filter(inboxFilter, messages))
+    sent = list(filter(sentFilter, messages))
 
     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]
+        [(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]]
@@ -1480,7 +1494,7 @@ def theme():
             # Redefine decorated_name
             g['decorated_name'] = lambda x: color_func(
                 c['DECORATED_NAME'])(
-                '[' + x + ']: ')
+                '[' + x + ']: ', rl=True)
             printNicely(green('Theme changed.'))
         except:
             printNicely(red('No such theme exists.'))
@@ -1543,7 +1557,7 @@ def config():
             if key == 'THEME':
                 c['THEME'] = reload_theme(value, c['THEME'])
                 g['decorated_name'] = lambda x: color_func(
-                    c['DECORATED_NAME'])('[' + x + ']: ')
+                    c['DECORATED_NAME'])('[' + x + ']: ', rl=True)
             elif key == 'PREFIX':
                 g['PREFIX'] = u2str(emojize(format_prefix(
                     listname=g['listname'],