Files
claudetools/clients/cascades-tucson/reports/user-detail-batches/_merge-all.py
Howard Enos 74890d51ec sync: auto-sync from ACG-TECH03L at 2026-04-18 14:28:21
Author: Howard Enos
Machine: ACG-TECH03L
Timestamp: 2026-04-18 14:28:21
2026-04-18 14:34:04 -07:00

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Merge batches 1-7 + batch-8/user-*.csv into all-users.csv."""
import csv
import glob
import os
BASE = r"C:\claudetools\clients\cascades-tucson\reports\user-detail-batches"
OUT = os.path.join(BASE, "all-users.csv")
sources = []
for i in range(1, 8):
sources.append(os.path.join(BASE, f"batch-{i}.csv"))
sources.extend(sorted(glob.glob(os.path.join(BASE, "batch-8", "user-*.csv"))))
fieldnames = None
rows = []
seen_upns = set()
for src in sources:
with open(src, "r", encoding="utf-8", newline="") as f:
reader = csv.DictReader(f)
if fieldnames is None:
fieldnames = reader.fieldnames
for row in reader:
upn_key = (row.get("UPN") or "").lower()
if upn_key in seen_upns:
print(f" SKIP duplicate: {upn_key} (from {os.path.basename(src)})")
continue
seen_upns.add(upn_key)
rows.append(row)
with open(OUT, "w", encoding="utf-8", newline="") as f:
w = csv.DictWriter(f, fieldnames=fieldnames, quoting=csv.QUOTE_MINIMAL)
w.writeheader()
for r in rows:
w.writerow(r)
print(f"\nWrote {len(rows)} rows from {len(sources)} source files -> {OUT}")