-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from offish/v0.0.2
add more stuff
- Loading branch information
Showing
13 changed files
with
286 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.