PyBot/config/check_config.py

84 lines
3.0 KiB
Python
Raw Normal View History

2024-12-25 18:40:20 +08:00
import yaml
from loguru import logger
# 清除所有已有的日志记录器配置
logger.remove()
2025-01-06 17:06:15 +08:00
logger.add("./resources/log/core.log",
2024-12-25 18:40:20 +08:00
format="{time:YYYY-MM-DD HH:mm:ss} - {level} - {name}:{function}:{line} - {message}",
rotation="100 MB",
compression="zip",
encoding="utf-8")
# shell终端打印日志
logger.add(lambda msg: print(msg),
format="{time:YYYY-MM-DD HH:mm:ss} - {level} - {name}:{function}:{line} - {message}")
def get_core_config():
# 加载参数
with open('./config/config.yaml', 'r', encoding="utf-8") as file:
config = yaml.safe_load(file)
2025-01-06 17:06:15 +08:00
debug = config.get('debug', 'False') # 使用 get 方法提供默认值
if str(debug).lower() == "true": # 统一转换为小写进行比较
2025-01-06 14:26:37 +08:00
logger.debug("Debug mode is on")
logger.debug(f"Loaded config: {config}") # 输出加载的配置
2024-12-25 18:40:20 +08:00
2025-01-02 13:00:43 +08:00
time_choice = int(f"{config['time_mode']}")
choice = config['mode'] # 假设 mode 是一个列表
2024-12-25 18:40:20 +08:00
e_hour = int(config.get('e_hour', '4')) # 默认循环时间为4小时
fs_activate = f"{config['fs_activate']}"
if fs_activate == "True":
fs_key = config.get('fs_key')
fs_secret = config.get('fs_secret')
if not fs_key or not fs_secret:
logger.error("飞书相关配置不能为空,请检查配置文件./config/config.yaml")
exit(5)
wx_activate = f"{config['wx_activate']}"
if wx_activate == "True":
wx_key = config.get('wx_key')
if not wx_key:
logger.error("企业微信相关配置不能为空,请检查配置文件./config/config.yaml")
exit(5)
ding_activate = f"{config['ding_activate']}"
if ding_activate == "True":
ding_key = config.get('ding_key')
if not ding_key:
logger.error("钉钉相关配置不能为空,请检查配置文件./config/config.yaml")
exit(5)
lx_activate = f"{config['lx_activate']}"
if lx_activate == "True":
lx_key = config.get('lx_key')
if not lx_key:
logger.error("蓝信相关配置不能为空,请检查配置文件./config/config.yaml")
exit(5)
url_web = f"{config['url']}"
2025-01-02 13:00:43 +08:00
return e_hour, time_choice, choice, fs_activate, wx_activate, ding_activate, lx_activate, url_web
2024-12-25 18:40:20 +08:00
def get_debug_config():
with open('./config/config.yaml', 'r', encoding="utf-8") as file:
config = yaml.safe_load(file)
debug = f"{config['debug']}"
2025-01-02 13:00:43 +08:00
return debug
2025-01-23 10:20:10 +08:00
def get_keywords_config(item):
2025-01-02 13:00:43 +08:00
with open('./config/keywords.yaml', 'r', encoding="utf-8") as file:
config = yaml.safe_load(file)
2025-01-10 16:56:13 +08:00
if item == 'Doonsec':
Doonsec_switch = config.get('Doonsec-switch', False)
Doonsec = config['Doonsec']
return Doonsec_switch, Doonsec
elif item == 'Sogou-WX':
Sogou_WX = config['Sogou-WX']
return Sogou_WX
elif item == 'Baidu':
Baidu = config['Baidu']
return Baidu
else:
logger.error("参数错误,请检查./config/keywords.yaml")