Remove unused imports and clean up code structure across multiple files

This commit is contained in:
2025-05-13 11:39:47 +02:00
parent 99b9f50784
commit 0c8ecb2054
19 changed files with 84 additions and 32 deletions

View File

@@ -2,7 +2,7 @@ import re
from dataclasses import dataclass, field
from enum import Enum
import json
@dataclass
class Prof:
@@ -77,23 +77,19 @@ class BookData:
for key, value in data.items():
setattr(self, key, value)
@property
def to_dict(self):
return self.__dict__
"""Convert the dataclass to a dictionary."""
return json.dumps(self.__dict__, ensure_ascii=False)
def from_dataclass(self, dataclass):
for key, value in dataclass.__dict__.items():
setattr(self, key, value)
def from_string(self, data: str):
if not data.startswith("BookData"):
raise ValueError("No valid BookData string")
else:
pattern = r"(\w+)='([^']*)'"
data_dict = dict(re.findall(pattern, data))
# print(data_dict)
for key, value in data_dict.items():
setattr(self, key, value)
return self
data = json.loads(data)
return BookData(**data)
@dataclass