Standardize formatting with black and apply ruff auto-fixes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import sys
|
|
import csv
|
|
|
|
from db_calls_card_creation import *
|
|
|
|
|
|
def clean_name(name):
|
|
return (
|
|
name.replace(".", "")
|
|
.replace("'", "")
|
|
.replace("-", " ")
|
|
.replace("í", "i")
|
|
.replace("é", "e")
|
|
.replace("ñ", "n")
|
|
.replace("á", "a")
|
|
)
|
|
|
|
|
|
def main(argv):
|
|
# Importing: https://docs.google.com/spreadsheets/d/1Gcgk4P8rJqX7mHO-OKPuM2FXBWNkDNZ8LNFA6DeaNck/edit#gid=72732162
|
|
# Player Database from Columns tab
|
|
file_name = "data-input/players.csv"
|
|
|
|
with open(file_name, "r") as file:
|
|
reader = csv.reader(file)
|
|
all_players = []
|
|
|
|
for row in reader:
|
|
if "sba" not in row[0]:
|
|
all_players.append(
|
|
{
|
|
"name": clean_name(row[3]),
|
|
"fg_id": row[2],
|
|
"br_id": row[1],
|
|
"sba_id": row[0],
|
|
"offense_col": row[4],
|
|
"hand": row[5],
|
|
}
|
|
)
|
|
|
|
# TODO: will want to update this to check for existing record; get_or_create ?
|
|
with db.atomic():
|
|
for batch in chunked(all_players, 50):
|
|
ScoutPlayer.insert_many(batch).on_conflict_ignore().execute()
|
|
db.close()
|
|
|
|
print(f"Processed {len(all_players)} players")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|