mirror of
https://github.com/bspeice/playwithfriends
synced 2024-12-30 08:58:11 -05:00
Initial super-trivial server
This commit is contained in:
parent
8ede6abb9b
commit
0c92b0b9cd
@ -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}
|
||||
|
34
playwithfriends/server.py
Normal file
34
playwithfriends/server.py
Normal file
@ -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()
|
13
playwithfriends/static/index.html
Normal file
13
playwithfriends/static/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>The Server is Working!</h1>
|
||||
</body>
|
||||
</html>
|
15
playwithfriends/templates.py
Normal file
15
playwithfriends/templates.py
Normal file
@ -0,0 +1,15 @@
|
||||
from os import path
|
||||
from bottle import SimpleTemplate
|
||||
|
||||
|
||||
def render_template(template_name, params=None):
|
||||
if params is None:
|
||||
params = {}
|
||||
|
||||
package_dir = path.abspath(path.dirname(__file__))
|
||||
static_dir = path.join(package_dir, 'static')
|
||||
|
||||
with open(path.join(static_dir, template_name), 'r') as handle:
|
||||
template = SimpleTemplate(handle.read())
|
||||
|
||||
return template.render(**params)
|
Loading…
Reference in New Issue
Block a user