SuriRaja commited on
Commit
69dcca5
·
verified ·
1 Parent(s): 526d02f

Create parse_valve_schedule.py

Browse files
Files changed (1) hide show
  1. parse_valve_schedule.py +24 -0
parse_valve_schedule.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from typing import Dict
3
+
4
+ def parse_valve_schedule(file_text: str) -> Dict:
5
+ parsed_data = {
6
+ "Purchase Order No": "",
7
+ "Date": "",
8
+ "Supplier": "Valve Schedule Supplier",
9
+ "Items": []
10
+ }
11
+
12
+ try:
13
+ item_pattern = re.compile(r"(\w+)\s+([\w\s]+)\s+([\d.]+)\s+([\d.]+)")
14
+ for match in item_pattern.finditer(file_text):
15
+ parsed_data["Items"].append({
16
+ "Code": match.group(1),
17
+ "Description": match.group(2).strip(),
18
+ "Size": match.group(3),
19
+ "Quantity": match.group(4),
20
+ })
21
+ except Exception as e:
22
+ print(f"Error parsing Valve Schedule PO: {e}")
23
+
24
+ return parsed_data