Implement fetching of certain data from OpenF1
This commit is contained in:
@ -17,7 +17,10 @@ class ApiDriver():
|
||||
"team_name": str
|
||||
}
|
||||
|
||||
def __init__(self, response: dict[str, str]):
|
||||
def __init__(self, response: dict[str, str] | None):
|
||||
if response is None:
|
||||
return
|
||||
|
||||
for key in response:
|
||||
if not hasattr(self, key):
|
||||
raise Exception(f"Mismatch between response data and {type(self).__name__} (key={key})")
|
||||
@ -29,6 +32,13 @@ class ApiDriver():
|
||||
|
||||
print("ApiDriver:", self.__dict__)
|
||||
|
||||
def to_params(self) -> Dict[str, str]:
|
||||
params: Dict[str, str] = dict()
|
||||
for key in self.__dict__:
|
||||
params[str(key)] = str(self.__dict__[key])
|
||||
|
||||
return params
|
||||
|
||||
# Set all members to None so hasattr works above
|
||||
|
||||
session_key: int = None # type: ignore
|
||||
|
||||
@ -11,7 +11,10 @@ class ApiPosition():
|
||||
"position": int
|
||||
}
|
||||
|
||||
def __init__(self, response: dict[str, str]):
|
||||
def __init__(self, response: dict[str, str] | None):
|
||||
if response is None:
|
||||
return
|
||||
|
||||
for key in response:
|
||||
if not hasattr(self, key):
|
||||
raise Exception(f"Mismatch between response data and {type(self).__name__} (key={key})")
|
||||
@ -23,6 +26,13 @@ class ApiPosition():
|
||||
|
||||
print("ApiPosition:", self.__dict__)
|
||||
|
||||
def to_params(self) -> Dict[str, str]:
|
||||
params: Dict[str, str] = dict()
|
||||
for key in self.__dict__:
|
||||
params[str(key)] = str(self.__dict__[key])
|
||||
|
||||
return params
|
||||
|
||||
session_key: int = None # type: ignore
|
||||
meeting_key: int = None # type: ignore
|
||||
driver_number: int = None # type: ignore
|
||||
|
||||
@ -20,7 +20,10 @@ class ApiSession():
|
||||
"year": int
|
||||
}
|
||||
|
||||
def __init__(self, response: dict[str, str]):
|
||||
def __init__(self, response: dict[str, str] | None):
|
||||
if response is None:
|
||||
return
|
||||
|
||||
for key in response:
|
||||
if not hasattr(self, key):
|
||||
raise Exception(f"Mismatch between response data and {type(self).__name__} (key={key})")
|
||||
@ -32,6 +35,13 @@ class ApiSession():
|
||||
|
||||
print("ApiSession:", self.__dict__)
|
||||
|
||||
def to_params(self) -> Dict[str, str]:
|
||||
params: Dict[str, str] = dict()
|
||||
for key in self.__dict__:
|
||||
params[str(key)] = str(self.__dict__[key])
|
||||
|
||||
return params
|
||||
|
||||
location: str = None # type: ignore
|
||||
country_key: int = None # type: ignore
|
||||
country_code: str = None # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user