From 7ecccda9d827ba9fcaea8321b56b5e2f044f23f9 Mon Sep 17 00:00:00 2001 From: fzzinchemical Date: Thu, 13 Nov 2025 20:50:07 +0100 Subject: [PATCH] Fix atexit registration for JSON writing to ensure data is saved on exit --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b7f6b3c..91c0dc7 100644 --- a/main.py +++ b/main.py @@ -33,6 +33,8 @@ def write_json(file_path, data): with open(file_path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=4) +atexit.register(lambda: write_json(OUTPUT_FILE, {"tweets": _results})) + async def main(): global _results api = API() # or API("path-to.db") – default is `accounts.db` @@ -63,7 +65,6 @@ async def main(): await asyncio.sleep(random.uniform(17, 31)) - atexit.register(lambda: write_json(OUTPUT_FILE, {"tweets": _results})) if __name__ == "__main__": asyncio.run(main()) \ No newline at end of file