aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/print_mutual_friends.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-02-12 02:57:50 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-02-12 02:57:50 +0300
commitaf81c32b093c12f3fbaa013d8345ac3a04bbe80a (patch)
tree55b7bf7aa964cf055e4e73bf00927f7ca95b00ea /print_mutual_friends.py
parentREADME update (diff)
downloadvk-scripts-af81c32b093c12f3fbaa013d8345ac3a04bbe80a.tar.gz
vk-scripts-af81c32b093c12f3fbaa013d8345ac3a04bbe80a.zip
use the standard logging module & refactoring
Including more command line parameters & better usage messages.
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))