From ddc391da900f588836ef710dc5082b5ba212f7a9 Mon Sep 17 00:00:00 2001 From: offish Date: Sun, 29 Oct 2023 15:56:47 +0100 Subject: [PATCH] add prices and fix to_name funcs --- src/tf2_utils/__init__.py | 2 +- src/tf2_utils/prices_tf.py | 14 ++++++++++++-- src/tf2_utils/schema.py | 10 +++++++++- tests/test_schema.py | 11 +++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/tf2_utils/__init__.py b/src/tf2_utils/__init__.py index 53878e2..9008a03 100644 --- a/src/tf2_utils/__init__.py +++ b/src/tf2_utils/__init__.py @@ -1,6 +1,6 @@ __title__ = "tf2-utils" __author__ = "offish" -__version__ = "2.0.5" +__version__ = "2.0.6" __license__ = "MIT" from .sku import get_sku, get_sku_properties, sku_to_defindex diff --git a/src/tf2_utils/prices_tf.py b/src/tf2_utils/prices_tf.py index 40a1b2b..262d8b1 100644 --- a/src/tf2_utils/prices_tf.py +++ b/src/tf2_utils/prices_tf.py @@ -62,8 +62,18 @@ def __set_header(self, header: dict) -> None: def get_headers(self) -> dict: return self.header - def get_prices(self, page: int) -> dict: - return self.__get("/prices", {"page": page, "limit": 100, "order": "DESC"}) + def get_history( + self, sku: str, page: int = 1, limit: int = 100, order: str = "ASC" + ) -> dict: + return self.__get( + f"/history/{sku}", {"page": page, "limit": limit, "order": order} + ) + + def get_price(self, sku: str) -> dict: + return self.__get(f"/prices/{sku}") + + def get_prices(self, page: int, limit: int = 100, order: str = "DESC") -> dict: + return self.__get("/prices", {"page": page, "limit": limit, "order": order}) def update_price(self, sku: str) -> tuple[dict, int]: return self.__post(f"/prices/{sku}/refresh") diff --git a/src/tf2_utils/schema.py b/src/tf2_utils/schema.py index ebc50b3..c7b107b 100644 --- a/src/tf2_utils/schema.py +++ b/src/tf2_utils/schema.py @@ -11,7 +11,13 @@ def __init__( super().__init__(schema_items, defindex_names) def defindex_to_name(self, defindex: int) -> str: - return self.defindex_names.get(defindex, "") + if defindex == -50: + return "Random Craft Weapon" + + if defindex == -100: + return "Random Craft Hat" + + return self.defindex_names.get(str(defindex), "") def name_to_defindex(self, name: str) -> int: if name == "Random Craft Weapon": @@ -127,4 +133,6 @@ def name_to_sku(self, name: str) -> str: def sku_to_name(self, sku: str) -> str: defindex = sku_to_defindex(sku) + # TODO: add qualities and uncraftable here + # "reverse" name_to_sku return self.defindex_to_name(defindex) diff --git a/tests/test_schema.py b/tests/test_schema.py index 45852c6..a078fa5 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -56,6 +56,17 @@ def test_name_to_sku_qualities(self): self.assertEqual("378;13", haunted) self.assertEqual("378;14", collectors) + def test_defindex_to_name(self): + self.assertEqual("Tour of Duty Ticket", schema_items.defindex_to_name(725)) + self.assertEqual( + "Mann Co. Supply Crate Key", schema_items.defindex_to_name(5021) + ) + self.assertEqual("Random Craft Hat", schema_items.defindex_to_name(-100)) + self.assertEqual("Random Craft Weapon", schema_items.defindex_to_name(-50)) + self.assertEqual("Scrap Metal", schema_items.defindex_to_name(5000)) + self.assertEqual("Reclaimed Metal", schema_items.defindex_to_name(5001)) + self.assertEqual("Refined Metal", schema_items.defindex_to_name(5002)) + def test_sku_to_name_tod(self): name = schema_items.sku_to_name("725;6;uncraftable") self.assertEqual("Tour of Duty Ticket", name)