-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
55 lines (42 loc) · 1.75 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# !/usr/bin/env python
# -*- coding: UTF-8 -*-
# Author: araumi
# Email: [email protected]
# DateTime: 2023/6/22 上午2:19
import json
import os
from pathlib import Path
from .tools.collection import FrozenJSON
class Config(object):
root_path = Path(os.path.dirname(__file__))
config_path = root_path / "config.json"
def __init__(self):
self.config: FrozenJSON = self.load_config()
# -----------------------------------------
# logger
# -----------------------------------------
self.stream_level: str = str(self.config.logger.stream_level).upper()
self.file_level: str = str(self.config.logger.file_level).upper()
# -----------------------------------------
# service
# -----------------------------------------
# postgres
self.pg_host: str = str(self.config.service.postgres.host)
self.pg_port: int = int(self.config.service.postgres.port)
self.pg_user: str = str(self.config.service.postgres.user)
self.pg_password: str = str(self.config.service.postgres.password)
self.pg_database: str = str(self.config.service.postgres.database)
self.pg_min_size: int = int(self.config.service.postgres.min_size)
self.pg_max_size: int = int(self.config.service.postgres.max_size)
# -----------------------------------------
# strategy
# -----------------------------------------
self.max_workers: int = int(self.config.strategy.max_workers)
def load_config(self) -> FrozenJSON:
with open(self.config_path, "r") as f:
raw: dict = json.load(f)
return FrozenJSON(raw)
def to_dict(self) -> dict:
return self.config.to_dict()
if __name__ == "__main__":
pass