Fix atexit registration for JSON writing to ensure data is saved on exit
This commit is contained in:
3
main.py
3
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())
|
||||
Reference in New Issue
Block a user