diff --git a/live_status_ntf.py b/live_status_ntf.py index 5949d67..9ab7cc4 100644 --- a/live_status_ntf.py +++ b/live_status_ntf.py @@ -118,7 +118,7 @@ class MyHandler(FileSystemEventHandler): requests.post("http://turntf:18846/notify", json={"msg": msg}) -if __name__ == "__main__": +def main(): path = "logs" event_handler = MyHandler() observer = Observer() @@ -131,3 +131,7 @@ if __name__ == "__main__": except KeyboardInterrupt: observer.stop() observer.join() + + +if __name__ == "__main__": + main() diff --git a/main.py b/main.py index 76a1058..38ee90b 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ import time from typing import * import aiohttp +import live_status_ntf import redis_util as redis import blivedm @@ -61,6 +62,8 @@ def on_room_changed(new_room_ids): async def main(): + threading.Thread(target=live_status_ntf.main, daemon=True).start() + global TEST_ROOM_IDS flush_files() @@ -140,12 +143,14 @@ def init_session(): class JsonlLogger(blivedm.BaseHandler): def _global_callback(self, client: ws_base.WebSocketClientBase, message: dict): if client.room_id not in log_files: - log_files[client.room_id] = open(f"logs/{client.room_id}.jsonl", "a", encoding="utf-8") + log_files[client.room_id] = open( + f"logs/{client.room_id}.jsonl", "a", encoding="utf-8") if "cmd" in message and message["cmd"] == "PREPARING": message["timestamp"] = int(time.time()) - log_files[client.room_id].write(f"{json.dumps(message, separators=(',', ':'), ensure_ascii=False)}\n") + log_files[client.room_id].write( + f"{json.dumps(message, separators=(',', ':'), ensure_ascii=False)}\n") # set log level to INFO