Skip to content

Commit

Permalink
Merge pull request #11 from offish/v2.0.6
Browse files Browse the repository at this point in the history
add prices and fix to_name funcs
  • Loading branch information
offish authored Oct 29, 2023
2 parents bac2fcd + ddc391d commit c0528f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tf2_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/tf2_utils/prices_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion src/tf2_utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)
11 changes: 11 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0528f6

Please sign in to comment.