diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-02-12 08:16:26 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-02-12 08:16:26 +0300 |
commit | 6bba781c496ad692d1bce21c561abab7e971e061 (patch) | |
tree | 8b2498ada3907e548eb6b29e2c127407493b3367 /mutual_friends.py | |
parent | refactoring (diff) | |
download | vk-scripts-6bba781c496ad692d1bce21c561abab7e971e061.tar.gz vk-scripts-6bba781c496ad692d1bce21c561abab7e971e061.zip |
rename the scripts
Diffstat (limited to 'mutual_friends.py')
-rw-r--r-- | mutual_friends.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mutual_friends.py b/mutual_friends.py new file mode 100644 index 0000000..9de77cb --- /dev/null +++ b/mutual_friends.py @@ -0,0 +1,34 @@ +# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com> +# This file is licensed under the terms of the MIT License. +# See LICENSE.txt for details. + +import sys + +from api import * + +def query_friends(api, user): + return api.friends_get(user.get_uid(), fields=User.Field.SCREEN_NAME) + +def format_user(user): + if user.has_last_name(): + return '{} {} ({})'.format(user.get_last_name(), user.get_first_name(), user.get_screen_name()) + else: + return '{} ({})'.format(user.get_first_name(), user.get_screen_name()) + +if __name__ == '__main__': + import argparse + 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() + + api = API(Language.EN) + users = api.users_get(args.user_ids, fields=User.Field.SCREEN_NAME) + + friend_lists = map(lambda user: frozenset(query_friends(api, user)), users) + mutual_friends = frozenset.intersection(*friend_lists) + if mutual_friends: + for friend in mutual_friends: + print(format_user(friend)) |