From 10c3b8dcad938fde6fe33e1611761a77c00f3af7 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 19 Mar 2017 12:28:09 -0400 Subject: [PATCH] Handle intersections of n users --- playwithfriends/intersections.py | 11 +++++------ tests/test_intersections.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/playwithfriends/intersections.py b/playwithfriends/intersections.py index d4feaad..0d6e63a 100644 --- a/playwithfriends/intersections.py +++ b/playwithfriends/intersections.py @@ -1,12 +1,11 @@ from playwithfriends import steam +from functools import reduce -def intersecting_games(steamid_left, steamid_right): +def intersecting_games(*args): api = steam.SteamAPI() - games_left = api.get_games(steamid_left) - games_right = api.get_games(steamid_right) + games_list = [api.get_games(steamid) for steamid in args] + ids_mutual = reduce(lambda l, r: set(l.keys()).intersection(r.keys()), games_list) - ids_mutual = set(games_left.keys()).intersection(games_right.keys()) - - return {game_id: games_left[game_id] for game_id in ids_mutual} + return {game_id: games_list[0][game_id] for game_id in ids_mutual} diff --git a/tests/test_intersections.py b/tests/test_intersections.py index 7767a0c..b2a2fb7 100644 --- a/tests/test_intersections.py +++ b/tests/test_intersections.py @@ -10,7 +10,7 @@ class TestIntersections(TestCase): steam_id_right = '76561198069992619' inter_games = intersections.intersecting_games( - steamid_left=steam_id_left, steamid_right=steam_id_right + steam_id_left, steam_id_right ) self.assertIn('Project CARS', inter_games.values())