diff options
Diffstat (limited to 'AllAboutData')
-rw-r--r-- | AllAboutData/getData.py | 32 | ||||
-rw-r--r-- | AllAboutData/utils.py (renamed from AllAboutData/utils/osSpecific.py) | 6 |
2 files changed, 16 insertions, 22 deletions
diff --git a/AllAboutData/getData.py b/AllAboutData/getData.py index 7b503fa..fe00c2d 100644 --- a/AllAboutData/getData.py +++ b/AllAboutData/getData.py @@ -13,17 +13,14 @@ Used API: https://rapidapi.com/theapiguy/api/free-nba/ ''' import os +import utils # Some functions to delete and create directories for data import requests import pandas as pd -from utils import osSpecific # Some functions to delete and create directories for data from dotenv import load_dotenv - -# Loading API key from environment variables. load_dotenv() API_KEY = os.getenv("API_KEY") - # API request details url = "https://free-nba.p.rapidapi.com/" headers = { @@ -31,27 +28,21 @@ headers = { "x-rapidapi-key": API_KEY } -# File name variables to store data in -if osSpecific.whichOs() == "windows": + +# Createing file name variables to store data in +if utils.whichOs() == "windows": teamsFile = "Data/NBAteams.csv" playersDir = "Data\Players\\" else: teamsFile = "Data/NBAteams.csv" playersDir = "Data/Players/" -# Createubg new Data dir to avoid duplicates (due appending) -osSpecific.deleteDataDir() -osSpecific.addDataDir() - - ###### Functions ###### def getTeamsData(url, headers): -''' -Requests Data about NBA teams and stores it. -Takes API url as first and its headers as second argument. -''' + '''Requests Data about NBA teams and stores it. + Takes API url as first and its headers as second argument.''' querystring = {"page": "0"} response = requests.request("GET", url+"teams", headers=headers, params=querystring) @@ -64,10 +55,8 @@ Takes API url as first and its headers as second argument. def getPlayerData(url, headers): -''' -Requests Data about NBA players and stores it, based on teams -Takes API url as first and its headers as second argument. -''' + '''Requests Data about NBA players and stores it, based on teams + Takes API url as first and its headers as second argument.''' print("Stared reading players data") @@ -111,6 +100,11 @@ Takes API url as first and its headers as second argument. if __name__ == "__main__": + + # Creating new Data dir to avoid duplicates (due appending) + utils.deleteDataDir() + utils.addDataDir() + getTeamsData(url, headers) getPlayerData(url, headers) diff --git a/AllAboutData/utils/osSpecific.py b/AllAboutData/utils.py index c89e65a..d5f36cf 100644 --- a/AllAboutData/utils/osSpecific.py +++ b/AllAboutData/utils.py @@ -3,7 +3,7 @@ import sys # terminal commands, which are unfortunately os-specific def whichOs(): -''' Returns "windows" if used os is windows. If not, returns "good" ''' + ''' Returns "windows" if used os is windows. If not, returns "good" ''' if sys.platform == "win32": return "windows" @@ -11,7 +11,7 @@ def whichOs(): return "good" def deleteDataDir(): -''' Removes Data directory from working directroy ''' + ''' Removes Data directory from working directroy ''' if whichOs() == "windows": os.system("rmdir \s Data") @@ -20,7 +20,7 @@ def deleteDataDir(): def addDataDir(): -''' Adds data directory from working directroy ''' + ''' Adds data directory from working directroy ''' if whichOs() == "windows": os.system("mkdir Data\Players") |