Skip to content

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
offish committed Feb 24, 2025
1 parent 3d62c07 commit 473f381
Show file tree
Hide file tree
Showing 25 changed files with 943 additions and 794 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

180 changes: 176 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,177 @@
.vscode
__pycache__
jsons
config.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Other
_build
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}
11 changes: 11 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


@pytest.fixture
def marketplace_tf_api_key() -> str:
return "api_key"


@pytest.fixture
def backpack_tf_token() -> str:
return "backpack_tf_token"
2 changes: 1 addition & 1 deletion src/tf2_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# flake8: noqa
__title__ = "tf2-utils"
__author__ = "offish"
__version__ = "2.2.0"
__version__ = "2.3.0"
__license__ = "MIT"

from .sku import *
Expand Down
9 changes: 4 additions & 5 deletions src/tf2_utils/backpack_tf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import requests

from dataclasses import dataclass, field
from hashlib import md5

from .schema import SchemaItemsUtils
from .sku import sku_to_quality, sku_is_craftable
from . import __title__
import requests

from . import __title__
from .schema import SchemaItemsUtils
from .sku import sku_is_craftable, sku_to_quality

__all__ = [
"Currencies",
Expand Down
42 changes: 21 additions & 21 deletions src/tf2_utils/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
self.key_price = key_price
self.item_is_not_pure = item_is_not_pure

self.__is_possible = False
self._is_possible = False
self.their_scrap = 0
self.our_scrap = 0
self.their_overview = {}
Expand Down Expand Up @@ -74,12 +74,8 @@ def get_pure_in_inventory(self, inventory: list[dict]) -> tuple[int, list[dict]]

return scrap, metal

def is_possible(self) -> bool:
return self.__is_possible

def __overview_to_items(
self, combination: list[str], inventory: list[dict]
) -> list[dict]:
@staticmethod
def _overview_to_items(combination: list[str], inventory: list[dict]) -> list[dict]:
items = []

for metal_name in combination:
Expand All @@ -97,12 +93,12 @@ def __overview_to_items(
return items

def get_currencies(self) -> tuple[list[dict], list[dict]]:
assert self.__is_possible, "Currencies does not add up"
assert self._is_possible, "Currencies does not add up"

their_items = self.__overview_to_items(
their_items = self._overview_to_items(
self.their_combination, self.their_inventory
)
our_items = self.__overview_to_items(self.our_combination, self.our_inventory)
our_items = self._overview_to_items(self.our_combination, self.our_inventory)

return their_items, our_items

Expand All @@ -125,7 +121,7 @@ def format_overview(pure: list[dict]) -> dict:

return overview

def __pick_currencies(self, user: str) -> tuple[bool, list[str]]:
def _pick_currencies(self, user: str) -> tuple[bool, list[str]]:
"""ref, ref, scrap, rec"""
overview = (
self.their_overview.copy() if user == "them" else self.our_overview.copy()
Expand Down Expand Up @@ -166,7 +162,7 @@ def __pick_currencies(self, user: str) -> tuple[bool, list[str]]:

return True, combination

def __does_add_up(self) -> bool:
def _adds_up(self) -> bool:
their_value = 0
our_value = 0

Expand All @@ -184,9 +180,9 @@ def __does_add_up(self) -> bool:

return their_value == our_value

def __set_combinations(self) -> bool:
success_our, our_combination = self.__pick_currencies("us")
success_their, their_combination = self.__pick_currencies("them")
def _set_combinations(self) -> bool:
success_our, our_combination = self._pick_currencies("us")
success_their, their_combination = self._pick_currencies("them")

if not success_our or not success_their:
return False
Expand All @@ -196,7 +192,7 @@ def __set_combinations(self) -> bool:

return True

def __has_enough(self) -> bool:
def _has_enough(self) -> bool:
temp_price = self.scrap_price

if self.item_is_not_pure:
Expand All @@ -214,11 +210,11 @@ def calculate(self) -> None:
self.their_overview = self.format_overview(their_pure)
self.our_overview = self.format_overview(our_pure)

if not self.__has_enough():
if not self._has_enough():
return

while self.__has_enough():
success = self.__set_combinations()
while self._has_enough():
success = self._set_combinations()

if success:
break
Expand All @@ -227,8 +223,12 @@ def calculate(self) -> None:
# try again, do this till we have either user does not have enough anymore
self.scrap_price += 1

if not self.__does_add_up():
if not self._adds_up():
return

# everything adds up and looks good
self.__is_possible = True
self._is_possible = True

@property
def is_possible(self) -> bool:
return self._is_possible
8 changes: 4 additions & 4 deletions src/tf2_utils/inventory.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import requests

from .providers.custom import Custom
from .providers.steamapis import SteamApis
from .providers.steamcommunity import SteamCommunity
from .providers.steamsupply import SteamSupply
from .providers.steamapis import SteamApis
from .providers.custom import Custom
from .sku import get_sku

import requests


def map_inventory(inventory: dict, add_skus: bool = False) -> list[dict]:
"""Matches classids and instanceids, merges these and
Expand Down
2 changes: 1 addition & 1 deletion src/tf2_utils/item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tf2_data import QUALITIES, KILLSTREAKS, EXTERIORS
from tf2_data import EXTERIORS, KILLSTREAKS, QUALITIES


class Item:
Expand Down
5 changes: 2 additions & 3 deletions src/tf2_utils/marketplace_tf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from .schema import SchemaItemsUtils
from .sku import sku_to_quality_name, sku_is_craftable

import time

import requests

from .schema import SchemaItemsUtils
from .sku import sku_is_craftable, sku_to_quality_name

__all__ = ["MarketplaceTF", "MarketplaceTFException", "SKUDoesNotMatch", "NoAPIKey"]

Expand Down
4 changes: 2 additions & 2 deletions src/tf2_utils/offer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .utils import account_id_to_steam_id

import enum

from .utils import account_id_to_steam_id


class TradeOfferState(enum.IntEnum):
Invalid = 1
Expand Down
Loading

0 comments on commit 473f381

Please sign in to comment.