Skip to content

Commit

Permalink
Merge pull request #2 from offish/v0.0.2
Browse files Browse the repository at this point in the history
add more stuff
  • Loading branch information
offish authored Oct 15, 2023
2 parents 7624b3b + 06dbf30 commit 5f3a2ef
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 98 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,28 @@
[![Discord](https://img.shields.io/discord/467040686982692865?color=7289da&label=Discord&logo=discord)](https://discord.gg/t8nHSvA)
[![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Item schemas, unusual effects, SKUs and more which can be useful for TF2 trading
Item schemas, unusual effects, SKUs and more which can be useful for TF2 trading. Dependant on [tf2-utils](https://github.com/offish/tf2-utils).

## Donate
- BTC: `bc1qntlxs7v76j0zpgkwm62f6z0spsvyezhcmsp0z2`
- [Steam Trade Offer](https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR)

## Setup
### Install
```bash
pip install tf2-data
# or
python -m pip install tf2-data
```

### Updating
```bash
pip install --upgrade tf2-data tf2-utils
# or
python -m pip install --upgrade tf2-data tf2-utils
```

## Testing
```bash
# tf2-data/
python -m unittest
18 changes: 18 additions & 0 deletions json/colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Genuine": "4D7455",
"1": "4D7455",
"Vintage": "476291",
"3": "476291",
"Unusual": "8650AC",
"5": "8650AC",
"Unique": "7D6D00",
"6": "7D6D00",
"Strange": "CF6A32",
"11": "CF6A32",
"Haunted": "38F3AB",
"13": "38F3AB",
"Collector's": "AA0000",
"14": "AA0000",
"Decorated Weapon": "FAFAFA",
"15": "FAFAFA"
}
8 changes: 8 additions & 0 deletions json/killstreaks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Basic": 1,
"1": "Basic",
"Specialized": 2,
"2": "Specialized",
"Professional": 3,
"3": "Professional"
}
12 changes: 12 additions & 0 deletions json/wears.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Factory New": 1,
"1": "Factory New",
"Minimal Wear": 2,
"2": "Minimal Wear",
"Field-Tested": 3,
"3": "Field-Tested",
"Well-Worn": 4,
"4": "Well-Worn",
"Battle Scarred": 5,
"5": "Battle Scarred"
}
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ authors = [
]
description = "Item schemas, unusual effects, SKUs and more which can be useful for TF2 trading"
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.10"
keywords = ["tf2", "data", "sku"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = ["tf2-sku", "tf2_utils"]
dependencies = ["tf2-utils"]
dynamic = ["version"]

[project.urls]
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

5 changes: 3 additions & 2 deletions src/tf2_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__title__ = "tf2-data"
__author__ = "offish"
__version__ = "0.0.1"
__version__ = "0.0.2"
__license__ = "MIT"

from .mapping import Data
from .schema import Schema, SchemaItems, IEconItems, EFFECTS
from .static import *
88 changes: 0 additions & 88 deletions src/tf2_data/mapping.py

This file was deleted.

111 changes: 111 additions & 0 deletions src/tf2_data/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from .utils import get_json_path, read_json_file, write_json_file, read_lib_json_file

from tf2_utils import IEconItems


SCHEMA_OVERVIEW_PATH = get_json_path("schema_overview")
SCHEMA_ITEMS_PATH = get_json_path("schema_items")
QUALITIES_PATH = get_json_path("qualities")
EFFECTS_PATH = get_json_path("effects")

EFFECTS = read_json_file(EFFECTS_PATH)


class SchemaItems:
def __init__(
self, schema_items: str | list[dict] = "", defindex_names: str | dict = ""
) -> None:
if not schema_items:
schema_items = read_lib_json_file("schema_items")

if not defindex_names:
defindex_names = read_lib_json_file("defindex_names")

if isinstance(schema_items, str):
schema_items = read_json_file(schema_items)

if isinstance(defindex_names, str):
defindex_names = read_json_file(defindex_names)

self.schema_items = schema_items
self.defindex_names = defindex_names

def map_defindex_name(self) -> dict:
data = {}

for item in self.schema_items:
name = item["item_name"]
defindex = item["defindex"]

data[defindex] = name
data[name] = defindex

self.defindex_names = data

return data


class Schema:
def __init__(
self, schema: dict | str = {}, api_key: str = "", language: str = "en"
) -> None:
if api_key:
schema = IEconItems(api_key).get_schema_overview(language)

if not schema:
schema = SCHEMA_OVERVIEW_PATH

if isinstance(schema, str):
schema = read_json_file(schema)

self.schema = schema

def set_effects(self) -> dict:
path = get_json_path("effects")
effects = self.schema["result"]["attribute_controlled_attached_particles"]

data = {}

for effect in effects:
effect_name = effect["name"]
effect_id = effect["id"]

# map both ways for ease of use
data[effect_name] = effect_id
data[effect_id] = effect_name

write_json_file(path, data)
return data

def set_qualities(self) -> dict:
path = get_json_path("qualities")
qualtiy_ids = self.schema["result"]["qualities"]
qualtiy_names = self.schema["result"]["qualityNames"]

data = {}

for q in qualtiy_ids:
quality_name = qualtiy_names[q]
quality_id = qualtiy_ids[q]

# map both ways for ease of use
data[quality_name] = quality_id
data[quality_id] = quality_name

write_json_file(path, data)
return data


class IEconItems(IEconItems):
def __init__(self, api_key: str) -> None:
super().__init__(api_key)

def set_schema_overview(self, language: str = "en") -> dict:
schema = self.get_schema_overview(language)
write_json_file(SCHEMA_OVERVIEW_PATH, schema)
return schema

def set_all_schema_items(self, language: str = "en", sleep: float = 5.0) -> list:
items = self.get_all_schema_items(language, sleep)
write_json_file(SCHEMA_ITEMS_PATH, items)
return items
79 changes: 79 additions & 0 deletions src/tf2_data/static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
QUALITIES = {
"Normal": 0,
"0": "Normal",
"Genuine": 1,
"1": "Genuine",
"rarity2": 2,
"2": "rarity2",
"Vintage": 3,
"3": "Vintage",
"rarity3": 4,
"4": "rarity3",
"Unusual": 5,
"5": "Unusual",
"Unique": 6,
"6": "Unique",
"Community": 7,
"7": "Community",
"Valve": 8,
"8": "Valve",
"Self-Made": 9,
"9": "Self-Made",
"Customized": 10,
"10": "Customized",
"Strange": 11,
"11": "Strange",
"Completed": 12,
"12": "Completed",
"Haunted": 13,
"13": "Haunted",
"Collector's": 14,
"14": "Collector's",
"Decorated Weapon": 15,
"15": "Decorated Weapon",
}

KILLSTREAKS = {
"Basic": 1,
"1": "Basic",
"Specialized": 2,
"2": "Specialized",
"Professional": 3,
"3": "Professional",
}

EXTERIORS = {
"Factory New": 1,
"1": "Factory New",
"Minimal Wear": 2,
"2": "Minimal Wear",
"Field-Tested": 3,
"3": "Field-Tested",
"Well-Worn": 4,
"4": "Well-Worn",
"Battle Scarred": 5,
"5": "Battle Scarred",
}

WEARS = EXTERIORS

COLORS = {
"Genuine": "4D7455",
"1": "4D7455",
"Vintage": "476291",
"3": "476291",
"Unusual": "8650AC",
"5": "8650AC",
"Unique": "7D6D00",
"6": "7D6D00",
"Strange": "CF6A32",
"11": "CF6A32",
"Haunted": "38F3AB",
"13": "38F3AB",
"Collector's": "AA0000",
"14": "AA0000",
"Decorated Weapon": "FAFAFA",
"15": "FAFAFA",
}

QUALITY_COLORS = COLORS
Loading

0 comments on commit 5f3a2ef

Please sign in to comment.