txt_parser.py 589 B

1234567891011121314151617181920
  1. # Most straight forward-copy paste :)
  2. import os
  3. class TXTParser:
  4. def __init__(self):
  5. pass
  6. def parse(self, file_path):
  7. if not os.path.exists(file_path):
  8. raise FileNotFoundError(f"Text file not found: {file_path}")
  9. with open(file_path, 'r', encoding='utf-8') as f:
  10. content = f.read()
  11. return content
  12. def save(self, content, output_path):
  13. os.makedirs(os.path.dirname(output_path), exist_ok=True)
  14. with open(output_path, 'w', encoding='utf-8') as f:
  15. f.write(content)