Esempio n. 1
0
def fetch_stats(request):
    if request == "about":
        return discord.Embed(
            title="About this bot",
            description=
            "A bot made by NSNull#6107, built on the opensource reddit bot HowStat by @pranavrc. Source code is available at [jamiebishop/discord-cricket-stat-bot](https://github.com/jamiebishop/discord-cricket-stat-bot)",
            color=discord.Color.green())

    # Create a mapper instance
    init = Mapper()

    # Create an URL mapping using the input request.
    try:
        mapped = init.map_string(request)
    except:
        return build_error_embed("Unable to parse your command.")

    # Find the player using the player name in the request.
    try:
        player_url = PlayerFinder(init.player_name)
    except:
        return build_error_embed(
            "Sorry, the service seems to be unavailable right now.")

    # Scrape and parse the statistics for the corresponding player.
    try:
        zeroed_in = player_url.zero_in()
        if not player_url.test_player:
            base_url = zeroed_in.replace("class=11;", "")
        else:
            base_url = zeroed_in.replace("class=1;", "")
    except:
        return build_error_embed("I couldn't find that, sorry.")

    # Create a Prettifier instance if it's a valid stats url.
    try:
        if base_url[-1] == ";":
            base_url += mapped
            if init.has_type_override:
                base_url = base_url.replace("type=allround;", "")
            prettifier = Prettifier(base_url, player_url.test_player)
        else:
            return build_error_embed("I couldn't find that, sorry.")
    except:
        return build_error_embed("I couldn't find that, sorry.")

    try:
        stat_dict = prettifier.parse_into_dict(init.class_allround)
    except Exception as e:
        print(e)
        return build_error_embed(
            "An unknown error occured. Contact <@507975140567416843> with the command which caused this error."
        )

    return build_embed_fields_from_stats(stat_dict, base_url, init)
Esempio n. 2
0
def fetch_stats(request):
    # Create a mapper instance
    init = Mapper()

    # Create an URL mapping using the input request.
    try:
        mapped = init.map_string(request)
    except:
        return "Uh, like..I mean, like..really..like, y'know...What?"

    # Find the player using the player name in the request.
    try:
        player_url = PlayerFinder(init.player_name)
    except:
        return "Sorry, the service seems to be unavailable right now."

    # Scrape and parse the statistics for the corresponding player.
    try:
        zeroed_in = player_url.zero_in()
        if not player_url.test_player:
            base_url = zeroed_in.replace("class=11;", "")
        else:
            base_url = zeroed_in.replace("class=1;", "")
    except:
        return "I couldn't find that, sorry."

    # Create a Prettifier instance if it's a valid stats url.
    try:
        if base_url[-1] == ";":
            base_url += mapped
            prettifier = Prettifier(base_url, player_url.test_player)
        else:
            return base_url
    except:
        return base_url

    # Format the content for a reddit comment.
    try:
        final = prettifier.prettify(init.class_allround)
    except:
        return request + ":\n\n" + "Ouch, nothing to see here, I think. " + \
                "You can check out the [records](%s)." % base_url

    # Url for complete stats.
    elaborate = "Detailed Stats [here.](%s)" % base_url

    return request + ':\n\n' + final + '\n\n' + elaborate
Esempio n. 3
0
def fetch_stats(request):
    # Create a mapper instance
    init = Mapper()

    # Create an URL mapping using the input request.
    try:
        mapped = init.map_string(request)
    except:
        return "Uh, like..I mean, like..really..like, y'know...What?"

    # Find the player using the player name in the request.
    try:
        player_url = PlayerFinder(init.player_name)
    except:
        return "Sorry, the service seems to be unavailable right now."

    # Scrape and parse the statistics for the corresponding player.
    try:
        zeroed_in = player_url.zero_in()
        if not player_url.test_player:
            base_url = zeroed_in.replace("class=11;", "")
        else:
            base_url = zeroed_in.replace("class=1;", "")
    except:
        return "I couldn't find that, sorry."

    # Create a Prettifier instance if it's a valid stats url.
    try:
        if base_url[-1] == ";":
            base_url += mapped
            prettifier = Prettifier(base_url, player_url.test_player)
        else:
            return base_url
    except:
        return base_url

    # Format the content for a reddit comment.
    try:
        final = prettifier.prettify(init.class_allround)
    except:
        return request + ":\n\n" + "Ouch, nothing to see here, I think. " + \
                "You can check out the [records](%s)." % base_url

    # Url for complete stats.
    elaborate = "Detailed Stats [here.](%s)" % base_url

    return request + ':\n\n' + final + '\n\n' + elaborate