import requests


def get_team(team_id, gw):
    """ Get the players in a team

    Args:
        team_id (int): Team id to get the data from
        gw (int): GW in which the team is taken

    Returns:
        (tuple): List of integers, Remaining budget
    """
    res = requests.get(
        'https://fantasy.premierleague.com/api/entry/' +
        f'{team_id}/event/{gw}/picks/').json()

    # Scrape GW before FH to get the team from GW prior
    if res['active_chip'] == 'freehit':
        res = requests.get(
            'https://fantasy.premierleague.com/api/entry/' +
            f'{team_id}/event/{gw-1}/picks/').json()

    # Adjust the player id with fplreview indices
    return [i['element'] for i in res['picks']], res['entry_history']['bank']