예제 #1
0
def headToHeadGames(player1, player2):
    base = '../../../../'

    if player1 in tntfl.get().players and player2 in tntfl.get().players:
        player1 = tntfl.get().getPlayer(player1)
        player2 = tntfl.get().getPlayer(player2)
        games = getSharedGames(player1, player2)
        return json.dumps([gameToJson(game, base) for game in games])
    else:
        abort(404)
예제 #2
0
파일: game_api.py 프로젝트: tredston/TNTFL
def game(game_time):
    try:
        base = '../../'
        game = next(g for g in tntfl.get().games if g.time == game_time)
        return json.dumps(gameToJson(game, base))
    except StopIteration:
        abort(404)
예제 #3
0
def activePlayers():
    def add(record, time, cur):
        record[int(time)] = {'count': cur}

    at = request.args.get('at') or ''
    times = parse_times(at)
    active_players = {}
    if len(times) > 0:
        [
            add(active_players, t,
                tntfl.get().getNumActivePlayers(t)) for t in times
        ]
    else:
        add(active_players, time.time(), tntfl.get().getNumActivePlayers())

    return json.dumps(active_players)
예제 #4
0
def recent():
    base = "../"
    limit = request.args.get('limit') or 10

    recent_games = [l for l in tntfl.get().games if not l.isDeleted()][-limit:]

    return json.dumps(
        [gameToJson(game, base) for game in reversed(recent_games)])
예제 #5
0
def games(games_from, games_to):
    limit = request.args.get('limit')
    include_deleted = request.args.get('includeDeleted')
    if include_deleted:
        include_deleted = int(include_deleted)

    base = ''
    games = tntfl.get().games
    games = filter_games(games, games_from, games_to, include_deleted)
    games = limit_games(games, limit)

    return json.dumps([gameToJson(game, base) for game in games])
예제 #6
0
def pundit():
    at = request.args.get('at') or ''
    times = parse_times(at)
    if len(times) > 0:
        try:
            punditry = dict([(t, {
                "facts": getFacts(t, tntfl.get())
            }) for t in times])
            return json.dumps(punditry)
        except StopIteration:
            abort(404)
    else:
        abort(400)
예제 #7
0
def ladder():
    base = "../"
    this_tntfl = tntfl.get()

    show_inactive = request.args.get('showInactive')
    include_players = request.args.get('players')

    games_from = request.args.get('gamesFrom')
    games_to = request.args.get('gamesTo')
    if games_from and games_to:
        time_range = (int(games_from), int(games_to))
        this_tntfl = TableFootballLadder(config.ladderFilePath, timeRange=time_range, transforms=PresetTransforms.transforms_for_ladder())

    return json.dumps(ladderToJson(this_tntfl, base, show_inactive, include_players))
예제 #8
0
파일: game_api.py 프로젝트: tredston/TNTFL
def add():
    url = urljoin(config.ladder_host, 'game/add')
    query = {
        'redPlayer': request.args.get('redPlayer'),
        'redScore': request.args.get('redScore'),
        'bluePlayer': request.args.get('bluePlayer'),
        'blueScore': request.args.get('blueScore'),
    }
    headers = {
        'Referer': 'https://{}/game/add/json'.format(request.host),
    }
    response = requests.post(url, params=query, headers=headers)
    if response.status_code is not 204:
        abort(response.status_code)

    tntfl.invalidate()

    base = '../../'
    game = tntfl.get().games[-1]
    return json.dumps(gameToJson(game, base))
예제 #9
0
def stats():
    base = '../'
    return json.dumps(getStatsJson(tntfl.get(), base))
예제 #10
0
def perPlayerStats(player):
    if player in tntfl.get().players:
        return json.dumps(perPlayerStatsToJson(getPerPlayerStats(tntfl.get().getPlayer(player))))
    else:
        abort(404)
예제 #11
0
def achievements(player):
    if player in tntfl.get().players:
        return json.dumps(getPlayerAchievementsJson(tntfl.get().getPlayer(player)))
    else:
        abort(404)
예제 #12
0
def playerGames(player):
    base = "../../../"
    if player in tntfl.get().players:
        return json.dumps([gameToJson(game, base) for game in tntfl.get().getPlayer(player).games])
    else:
        abort(404)
예제 #13
0
def player(player):
    if player in tntfl.get().players:
        return json.dumps(playerToJson(tntfl.get().getPlayer(player), tntfl.get()))
    else:
        abort(404)