Write state file and resume from there

Signed-off-by: Markus Birth <markus@birth-online.de>
This commit is contained in:
2026-05-14 00:26:51 +01:00
parent 8862723285
commit a1e217e511
+14
View File
@@ -185,6 +185,18 @@ def main():
print(f"Totals: Found [bold red]{len(to_block)}[/bold red] users not already on list.")
success_file = "successes.txt"
if os.path.isfile(success_file):
print("Found state file. Processing...")
removed = 0
with open(success_file, "rt") as f:
for line in f.readlines():
did = line.strip()
if did in to_block:
to_block.discard(did)
removed += 1
print(f"Removed [bold green]{removed}[/bold green] users that were already blocked on a previous run.")
task_add_to_list = prog.add_task(f"Adding users to list", total=len(to_block))
users_processed = 0
users_error = 0
@@ -194,6 +206,8 @@ def main():
print(f"[bold red]ERROR adding user [bold blue]{did_to_block}[/bold blue] to your list.")
users_error += 1
users_processed += 1
with open(success_file, "at") as f:
f.write(did_to_block + "\n")
prog.update(task_add_to_list, completed=users_processed)
if __name__ == "__main__":