Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
from os import getenv
from pathlib import Path

import pytest
from dotenv import load_dotenv

from src.tf2_utils.utils import read_json_file

assert load_dotenv()

MARKETPLACE_TF_API_KEY = getenv("MARKETPLACE_TF_API_KEY")
BACKPACK_TF_TOKEN = getenv("BACKPACK_TF_TOKEN")
EXPRESS_LOAD_API_KEY = getenv("EXPRESS_LOAD_API_KEY")


def get_item_data(file_name: str) -> dict:
path = Path(__file__).parent / f"tests/json/{file_name}.json"
return read_json_file(path)


# items
CRUSADERS_CROSSBOW = get_item_data("crusaders_crossbow")
UNCRAFTABLE_HAT = get_item_data("uncraftable_hat")
HONG_KONG_CONE = get_item_data("hong_kong_cone")
SPELLED_ITEM = get_item_data("spelled_item")
PAINTED_HAT = get_item_data("painted_hat")
ELLIS_CAP = get_item_data("ellis_cap")


@pytest.fixture
def steam_id() -> str:
return "76561198253325712"


@pytest.fixture
def account_id() -> str:
return "293059984"


@pytest.fixture
def marketplace_tf_api_key() -> str:
return MARKETPLACE_TF_API_KEY
Expand All @@ -28,3 +50,34 @@ def backpack_tf_token() -> str:
@pytest.fixture
def express_load_api_key() -> str:
return EXPRESS_LOAD_API_KEY


# items
@pytest.fixture
def crusaders_crossbow() -> dict:
return CRUSADERS_CROSSBOW


@pytest.fixture
def uncraftable_hat() -> dict:
return UNCRAFTABLE_HAT


@pytest.fixture
def hong_kong_cone() -> dict:
return HONG_KONG_CONE


@pytest.fixture
def spelled_item() -> dict:
return SPELLED_ITEM


@pytest.fixture
def painted_hat() -> dict:
return PAINTED_HAT


@pytest.fixture
def ellis_cap() -> dict:
return ELLIS_CAP
5 changes: 3 additions & 2 deletions src/tf2_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
__title__ = "tf2-utils"
__author__ = "offish"
__version__ = "2.3.2"
__version__ = "2.3.3"
__license__ = "MIT"

from .currency import CurrencyExchange
from .exceptions import InvalidInventory, TF2UtilsError
from .inventory import Inventory, map_inventory
from .item import Item
from .item_name import *
from .marketplace_tf import (
MarketplaceTF,
MarketplaceTFException,
Expand All @@ -27,4 +28,4 @@
from .sku import *
from .utils import *

# flake8: noqa
# flake8: noqa: F401, F403
94 changes: 94 additions & 0 deletions src/tf2_utils/item_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from tf2_data import EFFECTS, QUALITIES

__all__ = [
"has_festivized_in_name",
"has_uncraftable_in_name",
"has_non_craftable_in_name",
"is_craftable",
"has_australium_in_name",
"has_strange_in_name",
"has_basic_killstreak_in_name",
"has_specialized_killstreak_in_name",
"has_professional_killstreak_in_name",
"has_killstreak_in_name",
"get_effect_in_name",
"get_quality_from_name",
]

QUALITY_NAMES = [
"Genuine",
"Vintage",
"Unusual",
"Unique",
"Strange",
"Haunted",
"Collector's",
"Decorated Weapon",
]

EFFECT_NAMES = [i for i in EFFECTS.keys() if not i.isnumeric()]


def has_festivized_in_name(name: str) -> bool:
return "Festivized " in name


def has_uncraftable_in_name(name: str) -> bool:
return "Uncraftable " in name


def has_non_craftable_in_name(name: str) -> bool:
return "Non-Craftable " in name


def is_craftable(name: str) -> bool:
return not (has_uncraftable_in_name(name) or has_non_craftable_in_name(name))


def has_australium_in_name(name: str) -> bool:
return "Australium " in name


def has_strange_in_name(name: str) -> bool:
return "Strange " in name


def has_basic_killstreak_in_name(name: str) -> bool:
return name.startswith("Basic Killstreak ")


def has_specialized_killstreak_in_name(name: str) -> bool:
return name.startswith("Specialized ")


def has_professional_killstreak_in_name(name: str) -> bool:
return name.startswith("Professional ")


def has_killstreak_in_name(name: str) -> bool:
return (
has_basic_killstreak_in_name(name)
or has_specialized_killstreak_in_name(name)
or has_professional_killstreak_in_name(name)
)


def get_effect_in_name(name: str) -> int:
for effect in EFFECT_NAMES:
if effect in name:
return EFFECTS[effect]

return -1


def get_quality_from_name(name: str) -> int:
quality = 6

for part in name.split(" "):
if part not in QUALITY_NAMES:
continue

quality = QUALITIES[part]
break

return quality
Loading