From 7e99f95da0fc82f77591268371ff2f68bccdf3b5 Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Fri, 18 Mar 2022 00:44:43 +0200 Subject: minor comment fixes --- AllAboutData/getData.py | 2 +- AllAboutData/utils.py | 6 +++--- api/main.py | 1 + api/routers/__init__.py | 1 + api/routers/get.py | 42 +++++++++++++++++++++++++----------------- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/AllAboutData/getData.py b/AllAboutData/getData.py index 5bf8367..61b213c 100644 --- a/AllAboutData/getData.py +++ b/AllAboutData/getData.py @@ -32,7 +32,7 @@ headers = { # Createing file name variables to store data in if utils.whichOs() == "windows": teamsFile = "Data/NBAteams.csv" - playersDir = "Data\Players\\" + playersDir = "Data\\Players\\" else: teamsFile = "Data/NBAteams.csv" playersDir = "Data/Players/" diff --git a/AllAboutData/utils.py b/AllAboutData/utils.py index d5f36cf..af25735 100644 --- a/AllAboutData/utils.py +++ b/AllAboutData/utils.py @@ -5,7 +5,7 @@ import sys def whichOs(): ''' Returns "windows" if used os is windows. If not, returns "good" ''' - if sys.platform == "win32": + if sys.platform == "win32": return "windows" else: return "good" @@ -14,7 +14,7 @@ def deleteDataDir(): ''' Removes Data directory from working directroy ''' if whichOs() == "windows": - os.system("rmdir \s Data") + os.system("rmdir \\s Data") else: os.system("rm -r Data") @@ -23,7 +23,7 @@ def addDataDir(): ''' Adds data directory from working directroy ''' if whichOs() == "windows": - os.system("mkdir Data\Players") + os.system("mkdir Data\\Players") else: os.system("mkdir -p Data/Players") print("Created new empty Data directory") diff --git a/api/main.py b/api/main.py index 4afe0d5..b61d975 100644 --- a/api/main.py +++ b/api/main.py @@ -4,6 +4,7 @@ from .routers import get app = FastAPI() +# To make it reachable from anywhere on web origins = ["*"] app.add_middleware( CORSMiddleware, diff --git a/api/routers/__init__.py b/api/routers/__init__.py index e69de29..085b949 100644 --- a/api/routers/__init__.py +++ b/api/routers/__init__.py @@ -0,0 +1 @@ +from . import get diff --git a/api/routers/get.py b/api/routers/get.py index 7842cc3..7fd74ac 100644 --- a/api/routers/get.py +++ b/api/routers/get.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, APIRouter +from fastapi import APIRouter import numpy as np import pandas as pd @@ -6,8 +6,8 @@ router = APIRouter(tags=["Get requests"]) # Making relative paths. On windows slashes would be backwards -# Though, it is probably not a good way. And the API has to be activated -# from the project dir, for the paths to match. +# It is probably not a good way. +# API has to be activated from the project dir for the paths to match. relPathTeams = "AllAboutData/Data/NBAteams.csv" relPathPlayers = "AllAboutData/Data/Players/" @@ -22,31 +22,39 @@ def getTeamNames(): teamsDf = pd.read_csv(relPathTeams).to_dict() team_names = {} for el in range(len(teamsDf["name"])): - team_names.update({teamsDf["name"][el] : teamsDf["full_name"][el]}) + team_names.update({teamsDf["name"][el]: teamsDf["full_name"][el]}) return team_names @router.get("/teams") def getTeams(): + ''' + Returns all the teams of NBA, converted to json, + where each item represents one team. + ''' - # Converting the data and converting into dict to send + # Reading the data and converting into dict to send teamsDf = pd.read_csv(relPathTeams).to_dict() teams_dict = {} for el in range(len(teamsDf["name"])): teams_dict.update({el+1 : - {"Abbreviation" : teamsDf["abbreviation"][el], - "Name" : teamsDf["name"][el], - "FullName" : teamsDf["full_name"][el], - "City" : teamsDf["city"][el], - "Conference" : teamsDf["conference"][el], - "Division" : teamsDf["division"][el]} }) + {"Abbreviation": teamsDf["abbreviation"][el], + "Name": teamsDf["name"][el], + "FullName": teamsDf["full_name"][el], + "City": teamsDf["city"][el], + "Conference": teamsDf["conference"][el], + "Division": teamsDf["division"][el]} }) return teams_dict @router.get("/players/{team_name}") def getPlayers(team_name: str): + ''' + Returns players of requested team, converted to json, + where each item represents one player. + ''' teamNames = getTeamNames() team_name = team_name.capitalize() # Capitalizing in case url is given as lowercase @@ -58,14 +66,14 @@ def getPlayers(team_name: str): players_dict = {} for el in range(len(playersDf["first_name"])): players_dict.update({el+1 : - {"first_name" : playersDf["first_name"][el], - "last_name" : playersDf["last_name"][el], - "position" : playersDf["position"][el], - "height_feet" : playersDf["height_feet"][el], - "height_inches" : playersDf["height_inches"][el]} }) + {"first_name": playersDf["first_name"][el], + "last_name": playersDf["last_name"][el], + "position": playersDf["position"][el], + "height_feet": playersDf["height_feet"][el], + "height_inches": playersDf["height_inches"][el]} }) return players_dict else: - return {"Error 404" : "Team name Not Found"} + return {"Error 404": "Team name Not Found"} -- cgit v1.2.3