#!/usr/bin/env python3
"""
Script om de inhoud van een DOCX bestand te lezen
"""

import sys
from docx import Document

def read_docx(file_path):
    """Lees de tekstinhoud van een DOCX bestand"""
    try:
        doc = Document(file_path)
        full_text = []
        
        # Lees alle paragrafen
        for para in doc.paragraphs:
            full_text.append(para.text)
        
        # Lees tabellen als tekst
        for table in doc.tables:
            for row in table.rows:
                row_text = []
                for cell in row.cells:
                    row_text.append(cell.text.strip())
                full_text.append(" | ".join(row_text))
        
        return "\n".join(full_text)
    
    except Exception as e:
        print(f"Fout bij lezen van DOCX: {e}")
        return None

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Gebruik: python3 read_docx.py <docx_bestand>")
        sys.exit(1)
    
    file_path = sys.argv[1]
    content = read_docx(file_path)
    
    if content:
        print(content)
    else:
        print("Kon DOCX bestand niet lezen")
        sys.exit(1)