fix typo
[rainbowstream.git] / rainbowstream / rainbow.py
index b400529..0972390 100644 (file)
@@ -41,6 +41,7 @@ cmdset = [
     'ufav',
     's',
     'show',
+    'ls',
     'fl',
     'ufl',
     'h',
@@ -49,7 +50,7 @@ cmdset = [
 ]
 
 
-def draw(t, imgflg = 0, keyword=None, fil=[], ig=[]):
+def draw(t, iot=False, keyword=None, fil=[], ig=[]):
     """
     Draw the rainbow
     """
@@ -145,7 +146,7 @@ def draw(t, imgflg = 0, keyword=None, fil=[], ig=[]):
     printNicely(line3)
 
     # Display Image
-    if imgflg and media_url:
+    if iot and media_url:
         for mu in media_url:
             response = requests.get(mu)
             image_to_display(StringIO(response.content))
@@ -183,9 +184,10 @@ def parse_arguments():
         '--ignore',
         help='Ignore specific screen_name.')
     parser.add_argument(
-        '-img',
-        '--image',
-        help='Display all photo on terminal.')
+        '-iot',
+        '--image-on-term',
+        action='store_true',
+        help='Display all image on terminal.')
     return parser.parse_args()
 
 
@@ -294,7 +296,7 @@ def home():
     if g['stuff'].isdigit():
         num = g['stuff']
     for tweet in reversed(t.statuses.home_timeline(count=num)):
-        draw(t=tweet, imgflg=g['image'])
+        draw(t=tweet, iot=g['iot'])
     printNicely('')
 
 
@@ -310,7 +312,7 @@ def view():
         except:
             num = HOME_TWEET_NUM
         for tweet in reversed(t.statuses.user_timeline(count=num, screen_name=user[1:])):
-            draw(t=tweet, imgflg=g['image'])
+            draw(t=tweet, iot=g['iot'])
         printNicely('')
     else:
         printNicely(red('A name should begin with a \'@\''))
@@ -347,7 +349,7 @@ def favorite():
         tid = db.rainbow_query(id)[0].tweet_id
         t.favorites.create(_id=tid, include_entities=False)
         printNicely(green('Favorited.'))
-        draw(t.statuses.show(id=tid), imgflg=g['image'])
+        draw(t.statuses.show(id=tid), iot=g['iot'])
     except:
         printNicely(red('Omg some syntax is wrong.'))
 
@@ -392,7 +394,7 @@ def unfavorite():
         tid = db.rainbow_query(id)[0].tweet_id
         t.favorites.destroy(_id=tid)
         printNicely(green('Okay it\'s unfavorited.'))
-        draw(t.statuses.show(id=tid), imgflg=g['image'])
+        draw(t.statuses.show(id=tid), iot=g['iot'])
     except:
         printNicely(red('Sorry I can\'t unfavorite this tweet for you.'))
 
@@ -409,8 +411,8 @@ def search():
                 printNicely('Newest tweets:')
                 for i in reversed(xrange(SEARCH_MAX_RECORD)):
                     draw(t=rel[i],
-                        imgflg=g['image'],
-                        keyword=g['stuff'].strip()[1:])
+                         iot=g['iot'],
+                         keyword=g['stuff'].strip()[1:])
                 printNicely('')
             else:
                 printNicely(magenta('I\'m afraid there is no result'))
@@ -441,6 +443,35 @@ def show():
         printNicely(red('Sorry I can\'t show this image.'))
 
 
+def list():
+    """
+    List friends for followers
+    """
+    t = Twitter(auth=authen())
+    try:
+        target = g['stuff'].split()[0]
+        d = {'fl': 'followers', 'fr': 'friends'}
+        next_cursor = -1
+        rel = {}
+        # Cursor loop
+        while next_cursor != 0:
+            list = getattr(t, d[target]).list(screen_name=g['original_name'],
+                                              cursor=next_cursor,
+                                              skip_status=True,
+                                              include_entities=False,
+                                              )
+            for u in list['users']:
+                rel[u['name']] = '@' + u['screen_name']
+            next_cursor = list['next_cursor']
+        # Print out result
+        printNicely('All: ' + str(len(rel)) + ' people.')
+        for name in rel:
+            user = '  ' + cycle_color(name) + grey(' ' + rel[name] + ' ')
+            printNicely(user)
+    except:
+        printNicely(red('Omg some syntax is wrong.'))
+
+
 def follow():
     """
     Follow a user
@@ -448,8 +479,8 @@ def follow():
     t = Twitter(auth=authen())
     screen_name = g['stuff'].split()[0]
     if screen_name[0] == '@':
-        try :
-            t.friendships.create(screen_name=screen_name[1:],follow=True)
+        try:
+            t.friendships.create(screen_name=screen_name[1:], follow=True)
             printNicely(green('You are following ' + screen_name + ' now!'))
         except:
             printNicely(red('Sorry can not follow at this time.'))
@@ -464,8 +495,11 @@ def unfollow():
     t = Twitter(auth=authen())
     screen_name = g['stuff'].split()[0]
     if screen_name[0] == '@':
-        try :
-            t.friendships.destroy(screen_name=screen_name[1:],include_entities=False)
+        try:
+            t.friendships.destroy(
+                screen_name=screen_name[
+                    1:],
+                include_entities=False)
             printNicely(green('Unfollow ' + screen_name + ' success!'))
         except:
             printNicely(red('Sorry can not unfollow at this time.'))
@@ -523,8 +557,14 @@ def help():
         yellow('[id=12]') + '.\n'
     usage += s * 2 + green('s #AKB48') + ' will search for "' + \
         yellow('AKB48') + '" and return 5 newest tweet.\n'
-    usage += s * 2 + green('show image 12') + ' will show image in ' + \
-        yellow('[id=12]') + 'in your OS\'s image viewer.\n'
+    usage += s * 2 + green('show image 12') + ' will show image in tweet with ' + \
+        yellow('[id=12]') + ' in your OS\'s image viewer.\n'
+    usage += s * 2 + \
+        green('ls fl') + \
+        ' will list all followers (people who are following you).\n'
+    usage += s * 2 + \
+        green('ls fr') + \
+        ' will list all friends (people who you are following).\n'
     usage += s * 2 + green('fl @dtvd88') + ' will follow ' + \
         yellow('@dtvd88') + '.\n'
     usage += s * 2 + green('ufl @dtvd88') + ' will unfollow ' + \
@@ -582,6 +622,7 @@ def process(cmd):
             unfavorite,
             search,
             show,
+            list,
             follow,
             unfollow,
             help,
@@ -598,7 +639,7 @@ def listen():
     d = dict(zip(
         cmdset,
         [
-            ['public #', 'mine'],  # switch
+            ['public', 'mine'],  # switch
             [],  # home
             ['@'],  # view
             [],  # tweet
@@ -609,8 +650,9 @@ def listen():
             [],  # unfavorite
             ['#'],  # search
             ['image'],  # show image
-            [],  # follow
-            [],  # unfollow
+            ['fl', 'fr'],  # show image
+            ['@'],  # follow
+            ['@'],  # unfollow
             [],  # help
             [],  # clear
             [],  # quit
@@ -690,11 +732,11 @@ def stream(domain, args, name='Rainbow Stream'):
         elif tweet.get('text'):
             draw(
                 t=tweet,
-                imgflg=args.image,
+                iot=args.image_on_term,
                 keyword=args.track_keywords,
                 fil=args.filter,
                 ig=args.ignore,
-                )
+            )
 
 
 def fly():
@@ -712,5 +754,5 @@ def fly():
     g['reset'] = True
     g['prefix'] = True
     g['stream_pid'] = p.pid
-    g['image'] = args.image
-    listen()
\ No newline at end of file
+    g['iot'] = args.image_on_term
+    listen()