TgToFileSystem/configParse.py
2024-05-04 11:18:17 +08:00

30 lines
771 B
Python

import toml
from pydantic import BaseModel
class TgToFileSystemParameter(BaseModel):
class BaseParameter(BaseModel):
name: str
port: int
base: BaseParameter
class ApiParameter(BaseModel):
api_id: int
api_hash: str
tgApi: ApiParameter
class TgProxyParameter(BaseModel):
enable: bool
proxy_type: str
addr: str
port: int
proxy: TgProxyParameter
__cache_res = None
def get_TgToFileSystemParameter(path: str = "./config.toml", force_reload: bool = False) -> TgToFileSystemParameter:
global __cache_res
if __cache_res is not None and not force_reload:
return __cache_res
__cache_res = TgToFileSystemParameter.model_validate(toml.load(path))
return __cache_res