Example #1
0
def players(ctx, player_id, matches, date_from, date_to, competitions, status,
            limit, output_format, output_file):
    """Players Resource Endpoint"""
    if not player_id:
        click.secho("Aborted!, Please provide a specific player's id",
                    fg='red',
                    bold=True)
        return
    writer = get_writer(output_format, output_file)
    writer_func = writer.write_players
    payload = {}
    response = soccer.players(player_id).query.click_get()
    if any([limit, status, competitions, date_to, date_from]) and not matches:
        click.secho(
            'Aborted!, seems like you forgot to provide the --matches flag, you need that,'
            'to be able to add filters',
            fg='red')
        return
    if matches:
        payload = create_payload(date_from=date_from,
                                 date_to=date_to,
                                 competitions=competitions,
                                 status=status,
                                 limit=limit)
        writer_func = writer.write_matches
        response = soccer.players(player_id).matches.query.filter(
            payload).click_get()
    if response:
        writer_func(response)
    return
Example #2
0
def main(league, time, standings, team, live, use12hour, players, output_format, output_file, upcoming, lookup):
    """A CLI for live and past football scores from various football leagues"""
    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if live:
            get_live_scores(writer, use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer, upcoming, use12hour)
                return

        get_league_scores(league, time, writer, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #3
0
def main(league, time, standings, team, live, use12hour, players, output_format,
         output_file, upcoming, lookup, listcodes, apikey):
    """
    A CLI for live and past football scores from various football leagues.

    League codes:

    \b
    - CL: Champions League
    - PL: England Premier League
    - EL1: England League One
    - ELC: England Championship
    - FL1: French Ligue 1
    - FL2: French Ligue 2
    - BL: German Bundesliga
    - BL2: 2. Bundesliga
    - SA: Serie A
    - DED: Eredivisie
    - PPL: Primeira Liga
    - PD: Primera Division
    - SD: Segunda Division
    """
    global headers
    headers = {'X-Auth-Token': apikey}

    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if listcodes:
            list_team_codes()
            return

        if live:
            get_live_scores(writer, use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer, upcoming, use12hour)
                return

        get_league_scores(league, time, writer, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #4
0
def main(league, time, standings, team, live, use12hour, players, output_format,
         output_file, upcoming, lookup, listcodes, apikey):
    """
    A CLI for live and past football scores from various football leagues.

    League codes:

    \b
    - CL: Champions League
    - EPL: Premier League
    - EL1: League One
    - FL: Ligue 1
    - FL2: Ligue 2
    - BL: Bundesliga
    - BL2: 2. Bundesliga
    - BL3: 3. Liga
    - SA: Serie A
    - DED: Eredivisie
    - PPL: Primeira Liga
    - LLIGA: La Liga
    - SD: Segunda Division
    """
    global headers
    headers = {'X-Auth-Token': apikey}

    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if listcodes:
            list_team_codes()
            return

        if live:
            get_live_scores(writer, use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer, upcoming, use12hour)
                return

        get_league_scores(league, time, writer, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
 def setUp(self):
     dummy_key = 12345678901234567890123456789012
     headers = {'X-Auth-Token': dummy_key}
     TEAM_DATA = get_team_data()["teams"]
     TEAM_NAMES = {team["code"]: team["id"] for team in TEAM_DATA}
     LEAGUE_IDS = leagueids.LEAGUE_IDS
     self.dummy_url = "http://some_url"
     writer = get_writer()
     self.rq = RequestHandler(headers, LEAGUE_IDS, TEAM_NAMES, writer)
Example #6
0
 def setUp(self):
     dummy_key = 12345678901234567890123456789012
     headers = {'X-Auth-Token': dummy_key}
     TEAM_DATA = get_team_data()["teams"]
     TEAM_NAMES = {team["code"]: team["id"] for team in TEAM_DATA}
     LEAGUE_IDS = leagueids.LEAGUE_IDS
     self.dummy_url = "http://some_url"
     writer = get_writer()
     self.rq = RequestHandler(headers, LEAGUE_IDS, TEAM_NAMES, writer)
Example #7
0
def matches(ctx, match_id, date_from, date_to, status, competitions, use12hour,
            output_format, output_file):
    """Matches Resource Endpoint"""
    payload = create_payload(date_from=date_from,
                             date_to=date_to,
                             competitions=competitions,
                             status=status)
    response = soccer.matches(match_id).query.filter(payload).click_get()
    writer = get_writer(output_format, output_file)
    if response: writer.write_matches(response, use12hour)
    return
Example #8
0
def competitions(ctx, competition_id, areas, plan, output_format, output_file):
    """Competitions Resource Endpoint"""
    payload = create_payload(areas=areas, plan=plan)
    if ctx.invoked_subcommand is None:
        # dealing with the resource only, no subresources, add id
        response = soccer.competitions(competition_id).query.filter(
            payload).click_get()
        writer = get_writer(output_format, output_file)
        if response:
            writer.write_competitions(response)
        return
    else:
        ctx.obj['competition_id'] = competition_id
Example #9
0
def teams(ctx, season, stage, output_format, output_file):
    """Subresource for teams within competitions """
    # /v2/competitions/{id}/teams
    comp_id = ctx.obj.get('competition_id')
    if not comp_id:
        click.secho('Aborted!, You have to provide a competitions id',
                    fg='red',
                    bold=True)
        return
    else:
        payload = create_payload(season=season, stage=stage)
        response = soccer.competitions(comp_id).teams.query.filter(
            payload).click_get()
        writer = get_writer(output_format, output_file)
        if response: writer.write_teams(response)
        return
Example #10
0
def scorers(ctx, limit, output_format, output_file):
    """Scorers subresource for competitions resource"""
    comp_id = ctx.obj.get('competition_id')
    if not comp_id:
        click.secho('Aborted!, You have to provide a competition id',
                    fg='red',
                    bold=True)
        return
    else:
        payload = create_payload(limit=limit)
        response = soccer.competitions(comp_id).scorers.query.filter(
            payload).click_get()
        writer = get_writer(output_format, output_file)
        if response:
            writer.write_scorers(response)
        return
Example #11
0
def standings(ctx, standingtype, output_format, output_file):
    """
    Standings subresource for the competitions resource, only accessed and works
    if a competition id is present
    """
    comp_id = ctx.obj.get('competition_id')
    if not comp_id:
        click.secho('Aborted!, You have to provide a competition id',
                    fg='red',
                    bold=True)
        return
    else:
        payload = {'standingType': standingtype} if standingtype else {}
        response = soccer.competitions(comp_id).standings.query.filter(
            payload).click_get()
        writer = get_writer(output_format, output_file)
        if response:
            writer.write_standings(response)
Example #12
0
def main(league, time, standings, team, live, use12hour, players, output_format, output_file, upcoming, lookup, listcodes, apikey):
    """A CLI for live and past football scores from various football leagues"""
    global headers
    headers = {
        'X-Auth-Token': apikey
    }
    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if listcodes:
            list_team_codes()
            return

        if live:
            get_live_scores(writer, use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer, upcoming, use12hour)
                return

        get_league_scores(league, time, writer, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #13
0
def matches(ctx, date_from, date_to, status, matchday, group, season, stage,
            use12hour, output_format, output_file):
    """subresource of matches within competitions"""
    comp_id = ctx.obj.get('competition_id')
    if not comp_id:
        click.secho('Aborted!, You have to provide a competition id',
                    fg='red',
                    bold=True)
        return
    else:
        payload = create_payload(date_from=date_from,
                                 date_to=date_to,
                                 status=status,
                                 matchday=matchday,
                                 group=group,
                                 season=season,
                                 stage=stage)
        response = soccer.competitions(comp_id).matches.query.filter(
            payload).click_get()
        writer = get_writer(output_format, output_file)
        if response:
            writer.write_matches(response, use_12_hour_format=use12hour)
Example #14
0
def teams(ctx, team_id, venue, status, limit, matches, date_from, date_to,
          output_format, output_file):
    """Teams Resource Endpoint"""
    writer = get_writer(output_format, output_file)
    writer_func = writer.write_teams
    payload = {}
    response = soccer.teams(team_id).query.click_get()
    if any([venue, status, limit, date_from, date_to]) and not matches:
        click.secho(
            'Aborted!, seems like you forgot to provide the --matches flag, you need that'
            ' to be able to add filters',
            fg='red')
        return
    if matches:
        payload = create_payload(date_from=date_from,
                                 date_to=date_to,
                                 venue=venue,
                                 status=status,
                                 limit=limit)
        writer_func = writer.write_matches
        response = soccer.teams(team_id).matches.query.filter(
            payload).click_get()
    if response: writer_func(response)
Example #15
0
def main(league, time, standings, team, live, use12hour, players,
         output_format, output_file, upcoming, lookup, listcodes, apikey):
    """
    A CLI for live and past football scores from various football leagues.

    League codes:

    \b
    - CL: Champions League
    - PL: English Premier League
    - ELC: English Championship
    - EL1: English League One
    - FL1: French Ligue 1
    - FL2: French Ligue 2
    - BL: German Bundesliga
    - BL2: 2. Bundesliga
    - SA: Serie A
    - DED: Eredivisie
    - PPL: Primeira Liga
    - PD: Primera Division
    - SD: Segunda Division
    """
    headers = {'X-Auth-Token': apikey}

    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException(
                'Printing output to stdout and '
                'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)
        rh = RequestHandler(headers, LEAGUE_IDS, TEAM_NAMES, writer)

        if listcodes:
            list_team_codes()
            return

        if live:
            rh.get_live_scores(use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException(
                    'Please specify a league. '
                    'Example --standings --league=PL')
            if league == 'CL':
                raise IncorrectParametersException(
                    'Standings for CL - '
                    'Champions League not supported')
            rh.get_standings(league)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                rh.get_team_players(team)
                return
            else:
                rh.get_team_scores(team, time, upcoming, use12hour)
                return

        rh.get_league_scores(league, time, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(str(e), fg="red", bold=True)
Example #16
0
def main(league, lists, teams, team, players, fixtures, id, h2h, md, tf,
         competition, season, standings, output_format, output_file, apikey):

    if not key:
        click.secho('No API Token detected. \n'
                    'Please visit {0} and get an API Token, '
                    'which will be used by Soccer '
                    'to get access to the data.'.format(urls['web']),
                    fg="red",
                    bold=True)
        sys.exit(1)

    if fixtures:
        headers = {'X-Auth-Token': apikey, 'X-Response-Control': 'minified'}
    else:
        headers = {'X-Auth-Token': apikey}

    try:
        if output_format in ['stdout', 'fstdout', 'gstdout'] and output_file:
            raise IncorrectParametersException(
                'Printing output to stdout and '
                'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)
        rh = RequestHandler(headers, LEAGUE_IDS, TEAM_NAMES, writer)

        if lists:
            rh.get_lists()

        if standings:
            if not league:
                raise IncorrectParametersException(
                    'Please specify a league. '
                    'Example --standings --league=EPL')
            if league in ['CL', 'EC'
                          ] and output_format not in ['gstdout', 'gjson']:
                raise IncorrectParametersException(
                    'Standings for CL and EC '
                    'Champions League must use --gs(group stdout) '
                    'and --gjson(group json) as output format.')
            elif league not in ['CL', 'EC'
                                ] and output_format in ['gstdout', 'gjson']:
                raise IncorrectParametersException(
                    'Output format gstdout and gjson '
                    'only for EC and CL.')
            if md:
                rh.get_standings_by_matchday(league, md)
            else:
                rh.get_standings(league)

        if teams:
            if not league:
                raise IncorrectParametersException(
                    'Please specify a league. '
                    'Example --teams --league=PD')
            rh.get_teams(league)

        if competition:
            if league:
                rh.get_league(league)
            elif season:
                rh.get_leagues_by_season(season)
            else:
                rh.get_leagues()

        if players:
            if not team:
                raise IncorrectParametersException(
                    'Please specify a league. '
                    'Example --players --team=FCB')
            rh.get_players(team)

        if fixtures:
            if tf and md and league:
                tf = 'n' + str(tf) if tf > 0 else 'p' + str(abs(tf))
                rh.get_fixtures_by_md_tf_league(md, tf, league)
            elif tf and league:
                tf = 'n' + str(tf) if tf > 0 else 'p' + str(abs(tf))
                rh.get_fixtures_by_tf_league(tf, league)
            elif md and league:
                rh.get_fixtures_by_md_league(md, league)
            elif tf:
                tf = 'n' + str(tf) if tf > 0 else 'p' + str(abs(tf))
                rh.get_fixtures_by_tf(tf)
            elif team:
                rh.get_fixtures_by_team(team)
            elif league:
                rh.get_fixtures_by_league(league)
            elif id:
                rh.get_fixtures_by_id(id, h2h)

            if not league and not team and not id and not tf and not md:
                rh.get_fixtures()

    except IncorrectParametersException as e:
        click.secho(str(e), fg="red", bold=True)
Example #17
0
def areas(ctx, area_id, output_format, output_file):
    """Areas Resource Endpoint"""
    response = soccer.areas(area_id).query.click_get()
    writer = get_writer(output_format, output_file)
    if response: writer.write_areas(response)
    return
Example #18
0
def main(league, time, standings, extended, matchday, team, live, refresh,
         use12hour, players, output_format, output_file, upcoming, lookup,
         listcodes, listleagues, apikey):
    """
    A CLI for live and past football scores from various football leagues.

    League codes:

    \b
    - CL: Champions League
    - EPL: Premier League
    - EL1: League One
    - FL: Ligue 1
    - FL2: Ligue 2
    - BL: Bundesliga
    - BL2: 2. Bundesliga
    - BL3: 3. Liga
    - SA: Serie A
    - DED: Eredivisie
    - PPL: Primeira Liga
    - LLIGA: La Liga
    - SD: Segunda Division
    """
    global headers
    headers = {'X-Auth-Token': apikey}

    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException(
                'Printing output to stdout and '
                'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if listcodes:
            list_team_codes()
            return

        if listleagues:
            list_league_codes()
            return

        if live:
            if league:
                get_live_league(writer, use12hour, league, refresh)
            else:
                get_live_scores(writer, use12hour, refresh)
            return

        if standings:
            if not league:
                raise IncorrectParametersException(
                    'Please specify a league. '
                    'Example --standings --league=EPL')
            if matchday > 0:
                get_matchday_standings(league, writer, extended, matchday)
            else:
                get_standings(league, writer, extended)
            return

        if time < 1:
            raise IncorrectParametersException(
                'Please specify a time value greater than 0.')

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer, upcoming, use12hour)
                return

        get_league_scores(league, time, writer, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #19
0
def main(league, time, standings, team, live, use12hour, players,
         output_format, output_file, upcoming, lookup, listcodes, apikey):
    """
    A CLI for live and past football scores from various football leagues.

    League codes:

    \b
    - CL: Champions League
    - PL: English Premier League
    - ELC: English Championship
    - EL1: English League One
    - FL1: French Ligue 1
    - FL2: French Ligue 2
    - BL: German Bundesliga
    - BL2: 2. Bundesliga
    - SA: Serie A
    - DED: Eredivisie
    - PPL: Primeira Liga
    - PD: Primera Division
    - SD: Segunda Division
    """
    headers = {'X-Auth-Token': apikey}

    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)
        rh = RequestHandler(headers, LEAGUE_IDS, TEAM_NAMES, writer)

        if listcodes:
            list_team_codes()
            return

        if live:
            rh.get_live_scores(use12hour)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=PL')
            if league == 'CL':
                raise IncorrectParametersException('Standings for CL - '
                                                   'Champions League not supported')
            rh.get_standings(league)
            return

        if team:
            if lookup:
                map_team_id(team)
                return
            if players:
                rh.get_team_players(team)
                return
            else:
                rh.get_team_scores(team, time, upcoming, use12hour)
                return

        rh.get_league_scores(league, time, upcoming, use12hour)
    except IncorrectParametersException as e:
        click.secho(str(e), fg="red", bold=True)