update
This commit is contained in:
parent
7366d055e2
commit
91edac61e0
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user