Add sorter progress counters

The prompts used to arrive at this change since the previous commit

Add a counter to the verplaats_bestaand file

Any special observations that may be relevant for version management for this version. Be brief.

Audit mode now reports folder position and scanned message progress every 250 messages without running live mailbox scripts from Codex.
This commit is contained in:
2026-07-04 16:42:18 +02:00
parent e062db2fb6
commit d82f9792f0
2 changed files with 16 additions and 5 deletions
+15 -5
View File
@@ -36,6 +36,7 @@ LOG_FILE = Path(__file__).parent / "verplaats_log.json"
DRY_RUN = "--uitvoeren" not in sys.argv
AUDIT = "--audit" in sys.argv
PROGRESS_INTERVAL = 250
# Mappen die in één keer worden hernoemd/verplaatst (oud → nieuw).
@@ -126,6 +127,11 @@ def print_audit(title: str, by_source: Counter, by_destination: Counter):
print(f" {count:5d} {folder}")
def print_progress(folder: str, processed: int, total: int):
if processed == total or processed % PROGRESS_INTERVAL == 0:
print(f" Gescand: {processed}/{total} | {folder}")
def safe_select(session: ImapSession, log: dict, stap: str, folder: str, readonly: bool):
for attempt in range(2):
try:
@@ -302,7 +308,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
totaal_mislukt = 0
al_verwerkt = set(log.get("stap2_verwerkt", []))
for bron in bron_mappen:
for folder_index, bron in enumerate(bron_mappen, start=1):
status, data = safe_select(session, log, "stap2", bron, readonly=dry)
mail = session.mail
if status != "OK":
@@ -312,7 +318,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
n = int(data[0])
if n == 0:
continue
print(f" {bron}: {n} berichten")
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
status, data = safe_uid(
session, log, "stap2", bron, "", "SEARCH", "ALL", readonly=dry
@@ -331,6 +337,8 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
for uid in ids:
verwerkt += 1
if AUDIT:
print_progress(bron, verwerkt, len(ids))
uid_str = uid.decode()
log_key = f"{bron}:{uid_str}"
if log_key in al_verwerkt:
@@ -440,7 +448,7 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
audit_by_source = Counter()
audit_by_destination = Counter()
for bron in bron_mappen:
for folder_index, bron in enumerate(bron_mappen, start=1):
status, data = safe_select(session, log, "stap3", bron, readonly=dry)
mail = session.mail
if status != "OK":
@@ -448,10 +456,10 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
n = int(data[0])
if n == 0:
print(f" {bron}: leeg")
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: leeg")
continue
print(f" {bron}: {n} berichten")
print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
status, data = safe_uid(
session, log, "stap3", bron, "", "SEARCH", "ALL", readonly=dry
)
@@ -464,6 +472,8 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
mislukt = 0
for index, uid in enumerate(ids, start=1):
if AUDIT:
print_progress(bron, index, len(ids))
status, data = safe_uid(
session,
log,