由outputManager管理整个输出类及解析消息、分流消息功能,debug部分配置对接、xml导出部分配置对接

This commit is contained in:
2022-06-05 14:48:59 +08:00
parent 9fe1384b5d
commit 49a0715191
7 changed files with 153 additions and 107 deletions

View File

@ -1,3 +1,4 @@
from config.helper import config
from output.IOutput import IOutput
from typing import IO
import time
@ -10,13 +11,18 @@ class XMLWriter(IOutput):
def __init__(self):
self.file_mappings: "dict[str, IO[str]]" = {}
self.time_mappings: "dict[str, float]" = {}
self._file_name_pattern: "str" = config()['output']['xml']['file_pattern']
def _get_fd_by_room_id(self, room_id: str) -> IO[str]:
if room_id in self.file_mappings:
return self.file_mappings[room_id]
fd = open(f"{room_id}_{time.time()}.xml", "w", encoding="UTF-8")
cur_ts = time.time()
fd = open(self._file_name_pattern.format_map({
"room_id": room_id,
"ts": cur_ts
}), "w", encoding="UTF-8")
self.file_mappings[room_id] = fd
self.time_mappings[room_id] = time.time()
self.time_mappings[room_id] = cur_ts
return fd
def _close_fd_by_room_id(self, room_id: str):