Sfoglia il codice sorgente

Create txt_parser.py

Sanyam Bhutani 1 mese fa
parent
commit
d2e6933d85
1 ha cambiato i file con 20 aggiunte e 0 eliminazioni
  1. 20 0
      end-to-end-use-cases/data-tool/src/parsers/txt_parser.py

+ 20 - 0
end-to-end-use-cases/data-tool/src/parsers/txt_parser.py

@@ -0,0 +1,20 @@
+# Most straight forward-copy paste :)
+import os
+
+class TXTParser:
+    def __init__(self):
+        pass
+    
+    def parse(self, file_path):
+        if not os.path.exists(file_path):
+            raise FileNotFoundError(f"Text file not found: {file_path}")
+        
+        with open(file_path, 'r', encoding='utf-8') as f:
+            content = f.read()
+            
+        return content
+    
+    def save(self, content, output_path):
+        os.makedirs(os.path.dirname(output_path), exist_ok=True)
+        with open(output_path, 'w', encoding='utf-8') as f:
+            f.write(content)