1 Star 0 Fork 0

yuxinvalo/kqk_wechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
config.py 3.42 KB
一键复制 编辑 原始数据 按行查看 历史
yuxinvalo 提交于 2024-12-23 15:54 . add call dad, opt logs
import json
import logging
import os
class EnvConfig:
def __init__(self):
wxConf = self.load_config()
for key, value in wxConf.items():
setattr(self, key, value)
@staticmethod
def load_config() -> dict | None:
try:
config_path = ['./config.json', './config_template.json']
for path in config_path:
if os.path.exists(path):
with open(path, 'r', encoding='utf-8') as f:
config_str = f.read()
res_config = json.loads(config_str)
for name, value in os.environ.items():
name = name.upper()
if name in res_config:
try:
res_config[name] = eval(value)
except:
if value == "false":
res_config[name] = False
elif value == "true":
res_config[name] = True
else:
res_config[name] = value
logging.info(f"[config] Override the config by env conf {name}={value}")
logging.info("[INIT] Load config: {}".format(res_config))
return res_config
except Exception as e:
logging.critical("[config] Failed to load config json file, or path not exists. Process exit.")
logging.critical(e)
exit(1)
def reload_config(self):
wxConf = self.load_config()
for key, value in wxConf.items():
setattr(self, key, value)
envConfig = EnvConfig()
SERVER_HOST: str = 'http://192.168.3.3' if os.getenv("SERVER_HOST") is None else os.getenv("SERVER_HOST")
SERVER_PORT: int = 5005 if os.getenv("SERVER_PORT") is None else int(os.getenv("SERVER_PORT"))
DEFAULT_DATE_FORMAT: str = '%Y-%m-%d'
DEFAULT_TIME_FORMAT: str = DEFAULT_DATE_FORMAT + ' %H:%M:%S'
FILENAME_TIME_FORMAT: str = '%Y%M%d%H%M%S'
ROOT_PATH: str = os.path.dirname(__file__)
APP_DATA_DIR: str = os.path.join(ROOT_PATH, 'data')
GEN_FILE_DIR: str = os.path.join(APP_DATA_DIR, 'gen')
TEMPLATE_DIR: str = os.path.join(APP_DATA_DIR, 'templates')
TMP_FILE_ROOT_DIR: str = os.path.join(os.path.dirname(__file__), 'data', 'tmp')
LOG_DIR: str = os.path.join(ROOT_PATH, 'logs')
MINIO_BUCKET_NAME = 'kqk-bucket'
# ---WX---
HOT_RELOAD = True
GROUP_CHAT_PREFIX = [
"@咕噜蛋",
"咕噜蛋",
"金桔王"
]
SINGLE_CHAT_PREFIX = [
"咕噜蛋",
"金桔王",
]
GROUP_CHAT_REPLY_PREFIX = os.getenv("GROUP_CHAT_REPLY_PREFIX") if os.getenv("GROUP_CHAT_REPLY_PREFIX") is not None else ""
GROUP_CHAT_REPLY_SUFFIX = os.getenv("GROUP_CHAT_REPLY_SUFFIX") if os.getenv("GROUP_CHAT_REPLY_SUFFIX") is not None else ""
SINGLE_CHAT_REPLY_PREFIX = os.getenv("SINGLE_CHAT_REPLY_PREFIX") if os.getenv("SINGLE_CHAT_REPLY_PREFIX") is not None else ""
SINGLE_CHAT_REPLY_SUFFIX = os.getenv("SINGLE_CHAT_REPLY_SUFFIX") if os.getenv("SINGLE_CHAT_REPLY_SUFFIX") is not None else ""
GROUP_NAME_WHITE_LIST = os.getenv("GROUP_NAME_WHITE_LIST") if os.getenv("GROUP_NAME_WHITE_LIST") is not None else [
"鑫茂园",
"测试群"
]
# NICK_NAME_BLACK_LIST = []
NO_NEED_AT = False
ACCEPT_FILE_TYPE = [
"xlsx",
"xls"
]
FILE_MSG_SPLITER = ";;;"
CONCURRENCY_IN_SESSION = 1
EXPIRED_IN_SECONDS = 3600
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lainyu/kqk_wechat.git
[email protected]:lainyu/kqk_wechat.git
lainyu
kqk_wechat
kqk_wechat
main

搜索帮助