diff --git a/playwithfriends/intersections.py b/playwithfriends/intersections.py index 0d6e63a..3975667 100644 --- a/playwithfriends/intersections.py +++ b/playwithfriends/intersections.py @@ -6,6 +6,7 @@ def intersecting_games(*args): api = steam.SteamAPI() games_list = [api.get_games(steamid) for steamid in args] - ids_mutual = reduce(lambda l, r: set(l.keys()).intersection(r.keys()), games_list) + game_ids = [g.keys() for g in games_list] + ids_mutual = reduce(lambda l, r: set(l).intersection(r), game_ids) return {game_id: games_list[0][game_id] for game_id in ids_mutual} diff --git a/playwithfriends/server.py b/playwithfriends/server.py new file mode 100644 index 0000000..60846f1 --- /dev/null +++ b/playwithfriends/server.py @@ -0,0 +1,34 @@ +from bottle import route, run, request + +from playwithfriends.templates import render_template +from playwithfriends.steam import SteamAPI +from playwithfriends.intersections import intersecting_games + + +@route('/') +def index(): + return render_template('index.html') + + +@route('/get_friends') +def get_friends(): + api = SteamAPI() + steam64_id = api.get_steam64_from_profile(request.params['profile_url']) + friends_ids = api.get_friends_ids(steam64_id) + + return api.get_player_names(friends_ids) + + +@route('/get_games') +def get_games(): + player_ids = request.params['player_ids'].split(',') + inter_games = intersecting_games(*player_ids) + + return inter_games + + +def main(): + run(host='localhost', port=8000) + +if __name__ == '__main__': + main() diff --git a/playwithfriends/static/index.html b/playwithfriends/static/index.html new file mode 100644 index 0000000..3f8889d --- /dev/null +++ b/playwithfriends/static/index.html @@ -0,0 +1,13 @@ + + +
+ + + +