Skip to content

Commit b4ac2ac

Browse files
authored
Merge pull request #20 from offish/v2.3.3
v2.3.3
2 parents 30a5e57 + 9479530 commit b4ac2ac

File tree

12 files changed

+532
-362
lines changed

12 files changed

+532
-362
lines changed

conftest.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
from os import getenv
2+
from pathlib import Path
23

34
import pytest
45
from dotenv import load_dotenv
56

7+
from src.tf2_utils.utils import read_json_file
8+
69
assert load_dotenv()
710

811
MARKETPLACE_TF_API_KEY = getenv("MARKETPLACE_TF_API_KEY")
912
BACKPACK_TF_TOKEN = getenv("BACKPACK_TF_TOKEN")
1013
EXPRESS_LOAD_API_KEY = getenv("EXPRESS_LOAD_API_KEY")
1114

1215

16+
def get_item_data(file_name: str) -> dict:
17+
path = Path(__file__).parent / f"tests/json/{file_name}.json"
18+
return read_json_file(path)
19+
20+
21+
# items
22+
CRUSADERS_CROSSBOW = get_item_data("crusaders_crossbow")
23+
UNCRAFTABLE_HAT = get_item_data("uncraftable_hat")
24+
HONG_KONG_CONE = get_item_data("hong_kong_cone")
25+
SPELLED_ITEM = get_item_data("spelled_item")
26+
PAINTED_HAT = get_item_data("painted_hat")
27+
ELLIS_CAP = get_item_data("ellis_cap")
28+
29+
1330
@pytest.fixture
1431
def steam_id() -> str:
1532
return "76561198253325712"
1633

1734

35+
@pytest.fixture
36+
def account_id() -> str:
37+
return "293059984"
38+
39+
1840
@pytest.fixture
1941
def marketplace_tf_api_key() -> str:
2042
return MARKETPLACE_TF_API_KEY
@@ -28,3 +50,34 @@ def backpack_tf_token() -> str:
2850
@pytest.fixture
2951
def express_load_api_key() -> str:
3052
return EXPRESS_LOAD_API_KEY
53+
54+
55+
# items
56+
@pytest.fixture
57+
def crusaders_crossbow() -> dict:
58+
return CRUSADERS_CROSSBOW
59+
60+
61+
@pytest.fixture
62+
def uncraftable_hat() -> dict:
63+
return UNCRAFTABLE_HAT
64+
65+
66+
@pytest.fixture
67+
def hong_kong_cone() -> dict:
68+
return HONG_KONG_CONE
69+
70+
71+
@pytest.fixture
72+
def spelled_item() -> dict:
73+
return SPELLED_ITEM
74+
75+
76+
@pytest.fixture
77+
def painted_hat() -> dict:
78+
return PAINTED_HAT
79+
80+
81+
@pytest.fixture
82+
def ellis_cap() -> dict:
83+
return ELLIS_CAP

src/tf2_utils/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
__title__ = "tf2-utils"
22
__author__ = "offish"
3-
__version__ = "2.3.2"
3+
__version__ = "2.3.3"
44
__license__ = "MIT"
55

66
from .currency import CurrencyExchange
77
from .exceptions import InvalidInventory, TF2UtilsError
88
from .inventory import Inventory, map_inventory
99
from .item import Item
10+
from .item_name import *
1011
from .marketplace_tf import (
1112
MarketplaceTF,
1213
MarketplaceTFException,
@@ -27,4 +28,4 @@
2728
from .sku import *
2829
from .utils import *
2930

30-
# flake8: noqa
31+
# flake8: noqa: F401, F403

src/tf2_utils/item_name.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from tf2_data import EFFECTS, QUALITIES
2+
3+
__all__ = [
4+
"has_festivized_in_name",
5+
"has_uncraftable_in_name",
6+
"has_non_craftable_in_name",
7+
"is_craftable",
8+
"has_australium_in_name",
9+
"has_strange_in_name",
10+
"has_basic_killstreak_in_name",
11+
"has_specialized_killstreak_in_name",
12+
"has_professional_killstreak_in_name",
13+
"has_killstreak_in_name",
14+
"get_effect_in_name",
15+
"get_quality_from_name",
16+
]
17+
18+
QUALITY_NAMES = [
19+
"Genuine",
20+
"Vintage",
21+
"Unusual",
22+
"Unique",
23+
"Strange",
24+
"Haunted",
25+
"Collector's",
26+
"Decorated Weapon",
27+
]
28+
29+
EFFECT_NAMES = [i for i in EFFECTS.keys() if not i.isnumeric()]
30+
31+
32+
def has_festivized_in_name(name: str) -> bool:
33+
return "Festivized " in name
34+
35+
36+
def has_uncraftable_in_name(name: str) -> bool:
37+
return "Uncraftable " in name
38+
39+
40+
def has_non_craftable_in_name(name: str) -> bool:
41+
return "Non-Craftable " in name
42+
43+
44+
def is_craftable(name: str) -> bool:
45+
return not (has_uncraftable_in_name(name) or has_non_craftable_in_name(name))
46+
47+
48+
def has_australium_in_name(name: str) -> bool:
49+
return "Australium " in name
50+
51+
52+
def has_strange_in_name(name: str) -> bool:
53+
return "Strange " in name
54+
55+
56+
def has_basic_killstreak_in_name(name: str) -> bool:
57+
return name.startswith("Basic Killstreak ")
58+
59+
60+
def has_specialized_killstreak_in_name(name: str) -> bool:
61+
return name.startswith("Specialized ")
62+
63+
64+
def has_professional_killstreak_in_name(name: str) -> bool:
65+
return name.startswith("Professional ")
66+
67+
68+
def has_killstreak_in_name(name: str) -> bool:
69+
return (
70+
has_basic_killstreak_in_name(name)
71+
or has_specialized_killstreak_in_name(name)
72+
or has_professional_killstreak_in_name(name)
73+
)
74+
75+
76+
def get_effect_in_name(name: str) -> int:
77+
for effect in EFFECT_NAMES:
78+
if effect in name:
79+
return EFFECTS[effect]
80+
81+
return -1
82+
83+
84+
def get_quality_from_name(name: str) -> int:
85+
quality = 6
86+
87+
for part in name.split(" "):
88+
if part not in QUALITY_NAMES:
89+
continue
90+
91+
quality = QUALITIES[part]
92+
break
93+
94+
return quality

0 commit comments

Comments
 (0)