mirror of
https://github.com/bspeice/playwithfriends
synced 2024-12-21 21:08:09 -05:00
Handle intersections of n users
This commit is contained in:
parent
a7884d5fe0
commit
10c3b8dcad
@ -1,12 +1,11 @@
|
|||||||
from playwithfriends import steam
|
from playwithfriends import steam
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
def intersecting_games(steamid_left, steamid_right):
|
def intersecting_games(*args):
|
||||||
api = steam.SteamAPI()
|
api = steam.SteamAPI()
|
||||||
|
|
||||||
games_left = api.get_games(steamid_left)
|
games_list = [api.get_games(steamid) for steamid in args]
|
||||||
games_right = api.get_games(steamid_right)
|
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_list[0][game_id] for game_id in ids_mutual}
|
||||||
|
|
||||||
return {game_id: games_left[game_id] for game_id in ids_mutual}
|
|
||||||
|
@ -10,7 +10,7 @@ class TestIntersections(TestCase):
|
|||||||
steam_id_right = '76561198069992619'
|
steam_id_right = '76561198069992619'
|
||||||
|
|
||||||
inter_games = intersections.intersecting_games(
|
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())
|
self.assertIn('Project CARS', inter_games.values())
|
||||||
|
Loading…
Reference in New Issue
Block a user