Handle intersections of n users

This commit is contained in:
Bradlee Speice 2017-03-19 12:28:09 -04:00
parent a7884d5fe0
commit 10c3b8dcad
2 changed files with 6 additions and 7 deletions

View File

@ -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}

View File

@ -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())