From 7a287b64c4d094abf1a12d78d3e6132016121cbd Mon Sep 17 00:00:00 2001 From: Samuel Roach Date: Wed, 6 Jul 2022 22:09:52 +0100 Subject: [PATCH] Update version and removed _str --- README.md | 14 +++----- ergast_py/__init__.py | 4 +-- ergast_py/ergast.py | 80 +++++++++++++++++------------------------ pyproject.toml | 4 +-- tests/test_ergast_py.py | 2 +- 5 files changed, 42 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 53d616c..00897f8 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Queries can then be built up with function calls in a sequential manner. Once yo race_results = e.season(2008).round(5).get_results() # http://ergast.com/api/f1/drivers/massa -felipe_massa = e.driver_str("massa").get_driver() +felipe_massa = e.driver("massa").get_driver() # http://ergast.com/api/f1/current/constructorStandings/3 constructor_standings = e.season().standing(3).get_constructor_standings() @@ -112,19 +112,15 @@ More detail on the available functions within the ``Ergast()`` class is availabl | --------------- | ------------------------ | ------------------------------------------------------------------------------ | | season | year: int | If you call season with no arguments it will default to the current season | | round | round_no: int | If you call round with no arguments it will default to the last round | -| driver | driver: Driver | The Driver equivalent of ``driver_str`` | -| driver_str | driver: str | The String equivalent of ``driver``. Must use driver's driverId | -| constructor | constructor: Constructor | The Constructor equivalent of ``constructor_str`` | -| constructor_str | constructor: str | The String equivalent of ``constructor``. Must use constructor's constructorId | +| driver | driver: Driver | | +| constructor | constructor: Constructor | | | qualifying | position: int | Position at the end of qualifying | | sprint | position: int | | | grid | position: int | Position lined up on the grid | | result | position: int | | | fastest | position: int | Ranking in list of each drivers fastest lap | -| circuit | circuit: Circuit | The Circuit equivalent of ``circuit_str`` | -| circuit_str | circuit: str | The String equivalent of ``circuit``. Must use circuit's circuitId | -| status | status: int | The Integer equivalent of ``status_string``. Must use statusId | -| status_str | status: str | The String equivalent of ``status`` | +| circuit | circuit: Circuit | | +| status | status: int | Must use statusId or string representation | | standing | position: int | Position of Driver or Constructor in standing | | lap | lap_number: int | | | pit_stop | stop_number: int | | diff --git a/ergast_py/__init__.py b/ergast_py/__init__.py index 2a5516b..726a594 100644 --- a/ergast_py/__init__.py +++ b/ergast_py/__init__.py @@ -8,7 +8,7 @@ Basic usage: >>> import ergast_py >>> e = ergast_py.Ergast() - >>> e.driver_str("alonso").get_driver() + >>> e.driver("alonso").get_driver() Driver( driverId=alonso, permanentNumber=14, @@ -44,4 +44,4 @@ from ergast_py.models.standings_list import StandingsList from ergast_py.models.status import Status from ergast_py.models.timing import Timing -__version__ = '0.3.0' +__version__ = '0.5.0' diff --git a/ergast_py/ergast.py b/ergast_py/ergast.py index b12f455..373d491 100644 --- a/ergast_py/ergast.py +++ b/ergast_py/ergast.py @@ -26,7 +26,7 @@ class Ergast(): Build up the queries using the available functions. >>> e = ergast_py.Ergast() - >>> e.season(2021).round(1).driver_str("alonso") + >>> e.season(2021).round(1).driver("alonso") Get the data using ``.get_xyz()`` functions. @@ -88,42 +88,34 @@ class Ergast(): self.params["round"] = round_no return self - def driver(self, driver: Driver) -> Ergast: + def driver(self, driver) -> Ergast: """ Add a driver to the current query - >>> alonso = e.driver_str("alonso").get_driver() + >>> alonso = e.driver("alonso").get_driver() >>> e.driver(alonso).get_results() """ - self.params["driver"] = driver.driverId - return self - - def driver_str(self, driver: str) -> Ergast: - """ - Add a driver to the current query - - >>> e.driver_str("alonso").get_driver() - """ - self.params["driver"] = driver + if isinstance(driver, str): + self.params["driver"] = driver + elif isinstance(driver, Driver): + self.params["driver"] = driver.driverId + else: + raise TypeError("Function parameter must be of type Driver or str") return self def constructor(self, constructor: Constructor) -> Ergast: """ Add a constructor to the current query - >>> mercedes = e.constructor_str("mercedes").get_constructor() + >>> mercedes = e.constructor("mercedes").get_constructor() >>> e.constructor(mercedes).get_constructor_standings() """ - self.params["constructor"] = constructor.constructorId - return self - - def constructor_str(self, constructor: str) -> Ergast: - """ - Add a constructor to the current query - - >>> e.constructor_str("mercedes").get_constructor() - """ - self.params["constructor"] = constructor + if isinstance(constructor, str): + self.params["constructor"] = constructor + elif isinstance(constructor, Constructor): + self.params["constructor"] = constructor.constructorId + else: + raise TypeError("Function parameter must be of type Constructor or str") return self def qualifying(self, position: int) -> Ergast: @@ -171,41 +163,33 @@ class Ergast(): self.params["fastest"] = position return self - def circuit(self, circuit: Circuit) -> Ergast: + def circuit(self, circuit) -> Ergast: """ Add a circuit to the current query - >>> silverstone = e.circuit_str("silverstone").get_circuit() + >>> silverstone = e.circuit("silverstone").get_circuit() >>> e.circuit(silverstone) """ - self.params["circuit"] = circuit.circuitId + if isinstance(circuit, str): + self.params["circuit"] = circuit + elif isinstance(circuit, Circuit): + self.params["circuit"] = circuit.circuitId + else: + raise TypeError("Function parameter must be of type Circuit or str") return self - def circuit_str(self, circuit: str) -> Ergast: - """ - Add a circuit to the current query - - >>> e.circuit_str("silverstone").get_circuit() - """ - self.params["circuit"] = circuit - return self - - def status(self, status: int) -> Ergast: + def status(self, status) -> Ergast: """ Add a finishing status to the current query - >>> e.driver_str("alonso").status(2) + >>> e.driver("alonso").status(2) """ - self.params["status"] = status - return self - - def status_str(self, status: str) -> Ergast: - """ - Add a finishing status to the current query - - >>> e.season(2021).round(1).status_str("Disqualified") - """ - self.params["status"] = StatusType().string_to_id[status] + if isinstance(status, str): + self.params["status"] = status + elif isinstance(status, int): + self.params["status"] = StatusType().string_to_id[status] + else: + raise TypeError("Function parameter must be of type int or str") return self def standing(self, position: int) -> Ergast: diff --git a/pyproject.toml b/pyproject.toml index d1a77c2..42e4b79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ergast-py" -version = "0.3.0" +version = "0.5.0" description = "A comprehensive Python wrapper for the Ergast API." authors = ["Samuel Roach "] repository = "https://github.com/Samuel-Roach/ergast-py" @@ -8,7 +8,7 @@ license = "GPL-3.0-only" readme = "README.md" [tool.poetry.dependencies] -python = "^3.10" +python = "^3.9" requests = "^2.27.1" uritemplate = "^4.1.1" diff --git a/tests/test_ergast_py.py b/tests/test_ergast_py.py index 858d8f7..f3f3794 100644 --- a/tests/test_ergast_py.py +++ b/tests/test_ergast_py.py @@ -10,7 +10,7 @@ class TestErgastPy(): def test_version(self): """ Assert the version of the system """ - assert __version__ == '0.3.0' + assert __version__ == '0.5.0' def test_ergast(self): """ Basic test to check Ergast functions """