diff --git a/.gitignore b/.gitignore index 0cffcb3..cf74395 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -config.json \ No newline at end of file +config.json +*/**/__pycache__ \ No newline at end of file diff --git a/data_sources/base.py b/data_sources/base.py index 47f22a1..064f4a0 100644 --- a/data_sources/base.py +++ b/data_sources/base.py @@ -28,17 +28,19 @@ class DataSource(ABC): """ @abstractmethod - def get_team_data(self, team_number: int): - """Retrieve data for a specific team + def get_team_info(self, team_number: int): + """Retrieve information about a specific team team_number: int The team you want to retrieve data for """ @abstractmethod - def get_event_matches(self, event_code: str): + def get_event_matches(self, event_code: str, team_number: int | None = None): """Retrieve matches for a specific event event_code: str The eventcode for the event you want to retrieve match data from + team_number: int | None + The team you want to retrieve data for, if not provided will get all matches reguardless of teams """ @abstractmethod diff --git a/data_sources/tba.py b/data_sources/tba.py index bfa534e..adb38fc 100644 --- a/data_sources/tba.py +++ b/data_sources/tba.py @@ -20,16 +20,38 @@ class TheBlueAllianceConnector(DataSource): self.__api_token = api_token self.__observed_year = year self.__base_url = "https://www.thebluealliance.com/api/v3" - self._headers = {"X-TBA-Auth-Key": self.__api_token} + self.__headers = {"X-TBA-Auth-Key": self.__api_token} def get_status(self) -> tuple[DataSourceStatus, dict]: - pass + url = f"{self.__base_url}/status" + response = requests.get(url, headers=self.__headers) + if response.status_code == 200: + response_json = response.json() + return (DataSourceStatus.CONNECTED, {"extra_info": response_json}) + if response.status_code == 401: + return (DataSourceStatus.UNAUTHENTICATED, {}) - def get_team_data(self, team_number: int): - pass + def get_team_info(self, team_number: int) -> dict | None: + url = f"{self.__base_url}/team/frc{team_number}" + response = requests.get(url, headers=self.__headers) + if response.status_code == 200: + return response.json() + return None - def get_event_matches(self, event_code: str): - pass + def get_event_matches( + self, event_code: str, team_number: int | None = None + ) -> dict | None: + if team_number != None: + url = f"{self.__base_url}/team/frc{team_number}/event/{event_code}/matches" + response = requests.get(url, headers=self.__headers) + if response.status_code == 200: + return response.json() + else: + url = f"{self.__base_url}/event/{event_code}/matches" + response = requests.get(url, headers=self.__headers) + if response.status_code == 200: + return response.json() + return None - def get_team_performance_metrics(self, team_number, event_code=None): - pass + def get_team_performance_metrics(self, team_number, event_code=None) -> dict | None: + pass # TODO: Decide what performance metrics I care about from TBA, how to calculate them, etc.