Exporting Rabona teams into EXCEL files


The team page on Rabona doesn't let you filter/sort players by their properties. I've needed that functionality to plan my next season's roaster, so I have decided to hack a quick script to get the data and export it to excel (.xlsx format)

import pandas as pd
from rabona_python import RabonaClient

PLAYER_TYPE_GOAL_KEEPER = "1"
PLAYER_TYPE_DEFENDER = "2"
PLAYER_TYPE_MIDFIELDER = "3"
PLAYER_TYPE_ATTACKER = "4"

PLAYER_TYPE_MAP = {
    PLAYER_TYPE_GOAL_KEEPER: "goal keeper",
    PLAYER_TYPE_DEFENDER: "defender",
    PLAYER_TYPE_MIDFIELDER: "midfielder",
    PLAYER_TYPE_ATTACKER: "attacker",
}


def get_players(username):
    # https://api.rabona.io/team?user=emrebeyler
    rabona_client = RabonaClient()
    players = rabona_client.team(user=username)
    return players


def normalize_players(players):
    normalized_players = []
    for player in players:
        # human readable type
        player["position"] = PLAYER_TYPE_MAP.get(player["type"])
        player["OS"] = player["overall_strength"]
        player["GK"] = player["goalkeeping"]
        player["TP"] = player["teamplayer"]
        # not needed
        del player["type"]
        del player["ask_id"]
        del player["teamplayer"]
        del player["goalkeeping"]

        normalized_players.append(player)

    return normalized_players


def main(username):
    players = normalize_players(get_players(username)["players"])

    df = pd.DataFrame(players, columns=[
        "uid",
        "name",
        "position",
        "age",
        "OS",
        "GK",
        "defending",
        "passing",
        "dribbling",
        "shot",
        "headball",
        "form",
        "speed",
        "cleverness",
        "TP",
        "endurance",
        "vulnerability",
        "no_yellow_cards",
        "salary",
        "games_blocked",
        "games_injured",
        "for_sale",
        "frozen",
    ])

    print(df)

    df.to_excel(f"players_{username}.xlsx", header=True)

main("emrebeyler")

Just update the first argument in the main function with your username and let the script run. A new file (players_{username} will be created on the script's directory.) You need Python3, pandas, and rabona_python libraries.

Result


I might transform this into a small web app so that you can download the same excel without knowing any scripting spells. Just let me know if that would be something useful for you.

H2
H3
H4
3 columns
2 columns
1 column
12 Comments
Ecency