Loads database and fills gui with items
This commit is contained in:
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
1
modules/config/__init__.py
Normal file
1
modules/config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .settings import Config
|
||||
11
modules/config/model.py
Normal file
11
modules/config/model.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from typing import Dict, List
|
||||
from dataclasses import dataclass
|
||||
from dataclasses_json import dataclass_json
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class ConfigModel:
|
||||
database: str
|
||||
profile: str | None
|
||||
theme: str
|
||||
41
modules/config/settings.py
Normal file
41
modules/config/settings.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from modules.config.model import ConfigModel
|
||||
import json
|
||||
|
||||
|
||||
class Config:
|
||||
@staticmethod
|
||||
def default():
|
||||
return {
|
||||
"database": "default.gtabase",
|
||||
"profile": None,
|
||||
"theme": "Dark gray"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fix() -> None:
|
||||
try:
|
||||
with open("config.cfg", "w") as file:
|
||||
json.dump(Config.default(), file)
|
||||
except FileNotFoundError:
|
||||
Config.fix()
|
||||
|
||||
@staticmethod
|
||||
def get() -> ConfigModel:
|
||||
try:
|
||||
with open("config.cfg", "r") as file:
|
||||
return ConfigModel.from_dict(json.load(file))
|
||||
except:
|
||||
Config.fix()
|
||||
return Config.get()
|
||||
|
||||
@staticmethod
|
||||
def update(key: str, value: str) -> dict:
|
||||
with open("config.cfg", "r") as file:
|
||||
settings = json.load(file)
|
||||
|
||||
settings[key] = value
|
||||
|
||||
with open("config.cfg", "w") as file:
|
||||
json.dump(settings, file)
|
||||
|
||||
return settings
|
||||
0
modules/core/__init__.py
Normal file
0
modules/core/__init__.py
Normal file
15
modules/core/exceptions.py
Normal file
15
modules/core/exceptions.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from traceback import format_exception
|
||||
|
||||
|
||||
def hook(type_, value, traceback):
|
||||
print("[!] Error happened")
|
||||
print("Error type: ", type_.__name__)
|
||||
print("Error value: ", value)
|
||||
print("Error traceback: ", format_exception(type_, value, traceback)[2])
|
||||
|
||||
|
||||
def thread_hook(exception):
|
||||
print(f"[!] Error happened in {exception.thread}")
|
||||
print("Error type: ", exception.exc_type.__name__)
|
||||
print("Error value: ", exception.exc_value)
|
||||
print("Error traceback: ", format_exception(exception.exc_type, exception.exc_value, exception.exc_traceback)[2])
|
||||
2
modules/database/__init__.py
Normal file
2
modules/database/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .model import DatabaseModel
|
||||
from .database import Database
|
||||
15
modules/database/database.py
Normal file
15
modules/database/database.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import json
|
||||
from .model import DatabaseModel, default_database
|
||||
from modules.config import Config
|
||||
import os
|
||||
|
||||
|
||||
class Database:
|
||||
@staticmethod
|
||||
def get():
|
||||
try:
|
||||
return DatabaseModel.from_dict(json.load(open(Config.get().database)))
|
||||
except:
|
||||
with open(Config.get().database, 'w') as f:
|
||||
json.dump(default_database, f, indent=4)
|
||||
return DatabaseModel.from_dict(default_database)
|
||||
66
modules/database/model.py
Normal file
66
modules/database/model.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from typing import Dict, List
|
||||
from dataclasses import dataclass
|
||||
from dataclasses_json import dataclass_json
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class Item:
|
||||
item_name: str
|
||||
item_class: str
|
||||
item_type: str
|
||||
shop: str
|
||||
price: int
|
||||
image: str
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class Profile:
|
||||
profile_name: str
|
||||
owned_items: List[str]
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class DatabaseModel:
|
||||
items: Dict[str, Item] | None
|
||||
profiles: Dict[str, Profile] | None
|
||||
|
||||
|
||||
default_database = {
|
||||
"items": None,
|
||||
"profiles": None
|
||||
}
|
||||
|
||||
|
||||
aa = DatabaseModel.from_dict(
|
||||
{
|
||||
"items": {
|
||||
"sieg": {
|
||||
"item_name": "seig",
|
||||
"item_class": "meow",
|
||||
"item_type": "bebra44ka",
|
||||
"shop": "aaaaaaatb",
|
||||
"price": 100000000,
|
||||
"image": "https://magichitler.sieg/public/static/img/mama.png"
|
||||
},
|
||||
"aaaaaaaaaaaaa": {
|
||||
"item_name": "aaaaaaaaaaaaa",
|
||||
"item_class": "aaaaaaaaaaaaaaaaaaaa",
|
||||
"item_type": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"shop": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"price": 10000000000000000,
|
||||
"image": "https://sieg-heil.com/"
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"BarsTiger": {
|
||||
"profile_name": "BarsTiger",
|
||||
"owned_items": [
|
||||
"aaaaaaaaaaaaa"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user