diff options
author | Rasmus Luha <rasmus.luha@gmail.com> | 2022-03-16 02:14:39 +0200 |
---|---|---|
committer | Rasmus Luha <rasmus.luha@gmail.com> | 2022-03-16 02:14:39 +0200 |
commit | d834c529ae6c0c2d99888c23a37752e8de4fb127 (patch) | |
tree | e2620e48244536e9b116469ec2be91e2f9abdd0c |
Inital commit / teams Request
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | getData.py | 39 | ||||
-rw-r--r-- | osSpecific.py | 25 | ||||
-rw-r--r-- | requirements.txt | 11 |
4 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef2469e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +venv/ +.env +__pycache__/ +Data/ diff --git a/getData.py b/getData.py new file mode 100644 index 0000000..466ed45 --- /dev/null +++ b/getData.py @@ -0,0 +1,39 @@ +import pandas as pd +import requests +import osSpecific +from dotenv import load_dotenv +import os + +load_dotenv() +API_KEY = os.getenv("API_KEY") + + +# Delete Data Dir, if exists, and then create new. Have to do this to avoid duplicates, as Players are later appended to the files +osSpecific.deleteDataDir() +osSpecific.addDataDir() + +# File variables to but data into +if osSpecific.whichOs() == "windows": + teamsFile = "Data/NBAteams.csv" + playersDir = "Data\Players" +else: + teamsFile = "Data/NBAteams.csv" + playersDir = "Data/Players" + +# Requesting data about NBA teams +url = "https://free-nba.p.rapidapi.com/teams" +querystring = {"page":"0"} +headers = { + 'x-rapidapi-host': "free-nba.p.rapidapi.com", + 'x-rapidapi-key': API_KEY + } + +# Adding data to teams file +response = requests.request("GET", url, headers=headers, params=querystring) +teamsDf = pd.DataFrame(response.json()["data"]) +teamsDf.set_index("id") +teamsDf = teamsDf.drop("id", axis=1) + +teamsDf.to_csv(teamsFile) + +####################################################### diff --git a/osSpecific.py b/osSpecific.py new file mode 100644 index 0000000..09f5e59 --- /dev/null +++ b/osSpecific.py @@ -0,0 +1,25 @@ +import os +import sys + +# terminal commands, which are unfortunately os-specific + +def whichOs(): + if sys.platform == "win32": + return "windows" + else: + return "good" # Sorry, not sorry + +def deleteDataDir(): + if whichOs() == "windows": + os.system("rmdir \s Data") + else: + os.system("rm -r Data") + + +def addDataDir(): + if whichOs() == "windows": + os.system("mkdir Data\Players") + else: + os.system("mkdir -p Data/Players") + print("Created new empty Data directory") + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..89389bc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +certifi==2021.10.8 +charset-normalizer==2.0.12 +idna==3.3 +numpy==1.22.3 +pandas==1.4.1 +python-dateutil==2.8.2 +python-dotenv==0.19.2 +pytz==2021.3 +requests==2.27.1 +six==1.16.0 +urllib3==1.26.8 |