浏览代码

Create txt_parser.py

Sanyam Bhutani 1 月之前
父节点
当前提交
d2e6933d85
共有 1 个文件被更改,包括 20 次插入0 次删除
  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)