46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
"""配置加载模块"""
|
|
import os
|
|
import yaml
|
|
from pathlib import Path
|
|
|
|
class Config:
|
|
_instance = None
|
|
_config = None
|
|
|
|
def __new__(cls):
|
|
if cls._instance is None:
|
|
cls._instance = super().__new__(cls)
|
|
cls._instance._load_config()
|
|
return cls._instance
|
|
|
|
def _load_config(self):
|
|
config_path = Path(__file__).parent / "config" / "config.yaml"
|
|
with open(config_path, "r", encoding="utf-8") as f:
|
|
self._config = yaml.safe_load(f)
|
|
|
|
@property
|
|
def database(self):
|
|
return self._config.get("database", {})
|
|
|
|
@property
|
|
def redis(self):
|
|
return self._config.get("redis", {})
|
|
|
|
@property
|
|
def app(self):
|
|
return self._config.get("app", {})
|
|
|
|
@property
|
|
def crawlers(self):
|
|
return self._config.get("crawlers", {})
|
|
|
|
@property
|
|
def notification(self):
|
|
return self._config.get("notification", {})
|
|
|
|
@property
|
|
def tasks(self):
|
|
return self._config.get("tasks", {})
|
|
|
|
config = Config()
|