Exporting Rabona teams into EXCEL files
(Edited)
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.
Posted with STEMGeeks
0
0
0.000
Very handy!
Seems like every time I turn around lately I keep think I am in deep water trying to learn a little python 3 programming. Another aspect to look into the panda stuff. I wonder where it will all end, still fun trying to get out of the driveway. One day I may make it to the street.
Awesome! (:
That would be pretty cool.
will build something very quick
!ASH
!BEER
Great! Thank you!
Command accepted!
thanks
Aeneas is a blockchain project under development and a decentralized blogging platform based on Hive spesialized on the #social #politics #economics #indiejournalizm and all the #cryptocurrency related threads
Join Aeneas.Blog to earn more ASH for your unique content!
Dear, @emrebeyler, you have received
ASH
tokens!Join our Discord Server for further updates!
View or trade
BEER
.Hey @emrebeyler, here is a little bit of
BEER
from @stranger27 for you. Enjoy it!Learn how to earn FREE BEER each day by staking your
BEER
.Nice one buddy and congrats to your win in the night - I only struggle with this:
will release a small web app to get the data, wait a little bit :)
Great dude