Пример #1
0
def getStandings(code, mode='long'):
    """
    Function that delivers standings in text format.
    Queries the cache for the requested data, if not found,
    Loads the data from API and caches it

    Parameters:
    -----------
    code: str
        The ID of the league for which standings are required
    mode: 'long' or 'all', optional
        * defaults to 'long'
        * 'long' -> SNO, Team name, Matches Played, Points Obtained
        * 'all'  -> SNO, Team Code, Matches Played, Won, Drawn, Lost, Pts, Goal Difference

    Returns:
    --------
    str
        standings if code is valid, or an error message

    """

    try:
        if code not in LEAGUE_CODE:
            raise InvalidLeagueCodeException

        obj = fetchJSON(code, 'standings')
        if mode == 'all':
            return putTableAll(obj)
        return putTableLong(obj)

    except InvalidLeagueCodeException:
        return None
Пример #2
0
def getFixtures(code, limit: int):
    """
    Displays the fixtures in the requested league / team as an embed
    Fetches fixtures from JSON file and renders embed for it,
    Displays 'limit' matches

    Parameters:
    -----------
    code: str
        The ID of the league or team for which fixtures are required
    limit: int, optional
        Number of fixtures to display (default value of 5)
  
    Returns:
    --------
    discord.Embed
        Shows the fixtures as many as requested,
        Incase of invalid code, relevant help embed is returned

    """
    try:
        if limit < 0:
            raise InvalidLimitException

        mode = 'league'
        if code not in LEAGUE_CODE:
            if code in TEAM_ID:
                mode = 'team'
            else:
                return discord.Embed(
                    title='Please enter a valid code!',
                    description='Please Refer to **.team-codes** for team codes\
                        \nAnd **.league-codes** for league-codes',
                    color=0xf58300)

        obj = fetchJSON(code, 'fixtures')
        return putFixtures(obj, code, limit, mode)

    except InvalidLimitException:
        return discord.Embed(title='Limit must be greater than :zero:',
                             description="Enter a valid limit :smile:",
                             color=0xf58300)
Пример #3
0
def getMatches(code, limit: int):
    try:
        if limit < 0:
            raise InvalidLimitException

        mode = 'league'
        if code not in LEAGUE_CODE:
            if code in TEAM_ID:
                mode = 'team'
            else:
                return discord.Embed(
                    title='Please enter a valid code!',
                    description='Please Refer to **.team-codes** for team codes\
                        \nAnd **.league-codes** for league-codes',
                    color=0xf58300)

        obj = fetchJSON(code, 'live')
        return putMatches(obj, code, limit, mode)

    except InvalidLimitException:
        return discord.Embed(title='Limit must be greater than :zero:',
                             description="Enter a valid limit :smile:",
                             color=0xf58300)