aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/print_mutual_friends.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--print_mutual_friends.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/print_mutual_friends.py b/print_mutual_friends.py
index 6895a3c..b3beb39 100644
--- a/print_mutual_friends.py
+++ b/print_mutual_friends.py
@@ -8,26 +8,30 @@ def users_get(user_ids):
response = api.users_get(user_ids=','.join(user_ids),
fields='screen_name')
if len(response) < len(user_ids):
- print('Error: couldn\'t find at least one of the users!',
- file=sys.stderr)
- sys.exit(1)
+ raise RuntimeError('Couldn\'t find at least one of the users!')
return response
def friends_get(user_id):
return api.friends_get(user_id=user_id)
-def format_friend(user):
- s = '{} {}'.format(user['last_name'], user['first_name'])
+def extract_screen_name_or_uid(user):
if 'screen_name' in user:
- s += ' ({})'.format(user['screen_name'])
- return s
+ return user['screen_name']
+ return 'id' + str(user['uid'])
+
+def format_friend(user):
+ return '{} {} ({})'.format(
+ user['last_name'], user['first_name'],
+ extract_screen_name_or_uid(user))
if __name__ == '__main__':
import argparse
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(
+ description='Learn who your ex and her new boyfriend are both friends with.')
parser.add_argument(metavar='UID', dest='user_ids', nargs='+',
help='user IDs or "screen names"')
args = parser.parse_args()
+
users = users_get(args.user_ids)
user_ids = map(lambda user: user['uid'], users)
friend_lists = map(frozenset, map(friends_get, user_ids))