Skip to content

Commit 0896afb

Browse files
committed
minor changes
1 parent 7c19a79 commit 0896afb

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

docs/usage/currency.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from tf2_utils import CurrencyExchange, Inventory, map_inventory
22

3-
43
inventory_provider = Inventory("steamcommunity")
54

65
# Get our inventory of a user
@@ -26,7 +25,7 @@
2625

2726
currency.calculate()
2827

29-
if not currency.is_possible():
28+
if not currency.is_possible:
3029
print("Trade is not possible")
3130
# either no combination worked, or someone did not have enough pure
3231

src/tf2_utils/inventory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from .sku import get_sku
99

1010

11-
def map_inventory(inventory: dict, add_skus: bool = False) -> list[dict]:
11+
def map_inventory(
12+
inventory: dict, add_skus: bool = False, skip_untradable: bool = False
13+
) -> list[dict]:
1214
"""Matches classids and instanceids, merges these and
1315
adds `sku` to each item entry if `add_skus` is enabled"""
1416
mapped_inventory = []
@@ -18,6 +20,9 @@ def map_inventory(inventory: dict, add_skus: bool = False) -> list[dict]:
1820

1921
for asset in inventory["assets"]:
2022
for desc in inventory["descriptions"]:
23+
if skip_untradable and not desc["tradable"]:
24+
continue
25+
2126
if (
2227
asset["classid"] != desc["classid"]
2328
or asset["instanceid"] != desc["instanceid"]

src/tf2_utils/item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, item: dict) -> None:
99
self.tags = item.get("tags", [])
1010

1111
def is_tf2(self) -> bool:
12-
return self.item["appid"] == 440
12+
return int(self.item["appid"]) == 440
1313

1414
def is_tradable(self) -> bool:
1515
return self.item.get("tradable", 1) == 1

src/tf2_utils/sku.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
__all__ = [
99
"get_sku_properties",
1010
"is_sku",
11-
"is_pure",
11+
"is_key",
1212
"is_metal",
13+
"is_pure",
1314
"get_metal",
1415
"get_properties",
1516
"get_property",
@@ -64,14 +65,18 @@ def is_sku(item: str) -> bool:
6465
return item.find(";") != -1
6566

6667

67-
def is_pure(sku: str) -> bool:
68-
return sku in ["5000;6", "5001;6", "5002;6", "5021;6"]
68+
def is_key(sku: str) -> bool:
69+
return sku == "5021;6"
6970

7071

7172
def is_metal(sku: str) -> bool:
7273
return sku in ["5000;6", "5001;6", "5002;6"]
7374

7475

76+
def is_pure(sku: str) -> bool:
77+
return is_metal(sku) or is_key(sku)
78+
79+
7580
def get_metal(sku: str) -> int:
7681
assert is_metal(sku), f"sku {sku} is not metal"
7782

0 commit comments

Comments
 (0)