Spaces:
Running

hub / backend /scripts /check_headers_v3.py
Andre
deploy: snapshot c96b9ab -- Inventory Journals (Lagerforandringsjournal) na Contabilidade (v1.3.61)
77db408
Raw History Blame Contribute Delete
1.24 kB
import os
import csv
from io import StringIO
def _auto_decode(content: bytes) -> str:
if not content: return ""
# Explicitly try latin-1 if it looks like Visma export (common in Nordics)
if content.startswith(b'\xef\xbb\xbf'):
return content.decode('utf-8-sig')
try:
return content.decode('utf-8')
except:
try:
return content.decode('latin-1')
except:
return content.decode('cp1252', errors='replace')
assets_dir = r"backend/assets"
output = ""
for filename in sorted(os.listdir(assets_dir)):
if filename.endswith(".csv"):
path = os.path.join(assets_dir, filename)
with open(path, 'rb') as f:
content = f.read(4096)
text = _auto_decode(content)
first_line = text.split('\n')[0].strip()
# Clean up potential BOM or weird start
if first_line.startswith('\ufeff'): first_line = first_line[1:]
headers = [h.strip().strip('"') for h in first_line.split(';')]
output += f"File: {filename}\nHeaders: {', '.join(headers)}\n"
output += "-" * 40 + "\n"
with open("backend/headers_report.txt", "w", encoding="utf-8") as f:
f.write(output)
print("Done")