From 91edac61e00299323cf3dccfd3a9a0011427f251 Mon Sep 17 00:00:00 2001 From: tursom Date: Fri, 11 Oct 2024 14:00:52 +0800 Subject: [PATCH] update --- live_status_ntf.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/live_status_ntf.py b/live_status_ntf.py index eeb40f7..7f19705 100644 --- a/live_status_ntf.py +++ b/live_status_ntf.py @@ -8,7 +8,8 @@ import json import db import re -room_id_re = re.compile(r"\/(\d+).jsonl") +path = "logs" +room_id_re = re.compile(rf"{path}/(\d+).jsonl") class Room: @@ -36,7 +37,12 @@ _rooms: dict[str, Room] = {} def get_room(src_path): room_id = room_id_re.findall(src_path)[0] - return _rooms.get(room_id, Room(room_id)) + room = _rooms.get(room_id, None) + if room is None: + room = Room(room_id) + _rooms[room_id] = room + + return room class MyHandler(FileSystemEventHandler): @@ -44,7 +50,7 @@ class MyHandler(FileSystemEventHandler): if event.is_directory: return - if not event.src_path.endswith(".jsonl"): + if not room_id_re.match(event.src_path): return room: Room = get_room(event.src_path) @@ -67,7 +73,7 @@ class MyHandler(FileSystemEventHandler): if event.is_directory: return - if not event.src_path.endswith(".jsonl"): + if not room_id_re.match(event.src_path): return room: Room = get_room(event.src_path) @@ -84,7 +90,7 @@ class MyHandler(FileSystemEventHandler): if event.is_directory: return - if not event.src_path.endswith(".jsonl"): + if not room_id_re.match(event.src_path): return room = _rooms.get(event.src_path, Room()) @@ -118,8 +124,15 @@ class MyHandler(FileSystemEventHandler): requests.post("http://turntf:18846/notify", json={"msg": msg}) + + def main(): - path = "logs" + for f in os.listdir(path): + f = path+"/"+str(f) + if not room_id_re.match(f): + continue + get_room(f).position = os.path.getsize(f) + event_handler = MyHandler() observer = Observer() observer.schedule(event_handler, path, recursive=True)