36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Liste les valeurs distinctes des colonnes Etat et Status dans les CSV iTop.
|
|
|
|
Usage:
|
|
python tools/list_csv_etats.py <csv1> [<csv2> ...]
|
|
"""
|
|
import csv
|
|
import sys
|
|
from collections import Counter
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python tools/list_csv_etats.py <csv1> [<csv2> ...]")
|
|
sys.exit(1)
|
|
|
|
for path in sys.argv[1:]:
|
|
print(f"\n=== {path} ===")
|
|
with open(path, "r", encoding="utf-8-sig", newline="") as f:
|
|
sample = f.read(4096); f.seek(0)
|
|
delim = ";" if sample.count(";") > sample.count(",") else ","
|
|
reader = csv.DictReader(f, delimiter=delim)
|
|
rows = list(reader)
|
|
print(f"{len(rows)} lignes (delim={delim!r})")
|
|
print(f"Colonnes: {list(rows[0].keys()) if rows else []}")
|
|
|
|
for col in ("Etat", "État", "Status", "Environnement"):
|
|
if rows and col in rows[0]:
|
|
c = Counter((r.get(col) or "").strip() for r in rows)
|
|
print(f"\n[{col}]")
|
|
for v, n in c.most_common():
|
|
print(f" {v!r:30s} {n}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|