async def get_games_v1(testing: bool):
        game_sets = await asyncio.gather(*[
            CollegeBasketball.get_games(testing),
            Basketball.get_games(testing),
            Hockey.get_games(testing),
            Baseball.get_games(testing),
            Football.get_games(testing),
            CollegeFootball.get_games(testing),
        ])
        flatten_list = [game for game_set in game_sets for game in game_set]

        return flatten_list
    async def get_games_v4(testing: bool):
        print("[ALL] Beginning fetching all sports")
        game_sets = await asyncio.gather(*[
            Golf.get_games(testing),
            CollegeBasketball.get_games(testing),
            Basketball.get_games(testing),
            Hockey.get_games(testing),
            Baseball_v2.get_games(testing),
            Football_v2.get_games(testing),
            CollegeFootball_v2.get_games(testing),
        ])
        print("[ALL] Finished fetching all sports")
        flatten_list = [game for game_set in game_sets for game in game_set]

        return flatten_list
def lambda_handler(event, context):
    # First, hit the cache
    loop = asyncio.get_event_loop()
    print(event)
    sport = event["path"][1:]
    if sport in cache:
        item, timestamp = cache[sport]
        if time.time() - timestamp < REFRESH_WINDOW:
            return success_response(item)

    if sport == "college-basketball":
        result = wrap_games(loop.run_until_complete(CollegeBasketball.get_games(False)))
    elif sport == "basketball":
        result = wrap_games(loop.run_until_complete(Basketball.get_games(False)))
    elif sport == "hockey":
        result = wrap_games(loop.run_until_complete(Hockey.get_games(False)))
    elif sport == "college_football":
        result = wrap_games(loop.run_until_complete(CollegeFootball.get_games(False)))
    elif sport == "football":
        result = wrap_games(loop.run_until_complete(Football.get_games(False)))
    elif sport == "baseball":
        result = wrap_games(loop.run_until_complete(Baseball.get_games(False)))
    elif sport == "baseball_v2":
        result = wrap_games(loop.run_until_complete(Baseball_v2.get_games(False)))
    elif sport == "golf":
        result = wrap_games(loop.run_until_complete(Golf.get_games(False)))
    elif sport == "all":
        result = wrap_games(loop.run_until_complete(All.get_games_v1(False)))
    elif sport == "all_v2":
        result = wrap_games(loop.run_until_complete(All.get_games_v2(False)))
    elif sport == "all_v3":
        result = wrap_games(loop.run_until_complete(All.get_games_v3(False)))
    elif sport == "all_v4":
        result = wrap_games(loop.run_until_complete(All.get_games_v4(False)))
    else:
        result = None

    if result is not None:
        cache[sport] = (result, time.time())
        return success_response(result)

    print(f"ERROR: unknown sport {sport}")
    return None
示例#4
0
def basketball():
    return {"data": {"games": loop.run_until_complete(Basketball.get_games(testing))}}