Update app.py
Browse files
app.py
CHANGED
|
@@ -61,6 +61,7 @@ def parse_po_items_with_filters(text):
|
|
| 61 |
|
| 62 |
# Match the start of a new item
|
| 63 |
item_match = re.match(r"^(?P<Item>\d+)\s+(?P<Description>.+)", line)
|
|
|
|
| 64 |
if item_match:
|
| 65 |
print(f"Item match found: {item_match.group('Item')}") # Debugging
|
| 66 |
|
|
@@ -72,7 +73,7 @@ def parse_po_items_with_filters(text):
|
|
| 72 |
description_accumulator = [] # Reset description accumulator
|
| 73 |
print(f"Item {current_item['Item']} added to data.") # Debugging
|
| 74 |
|
| 75 |
-
#
|
| 76 |
current_item = {
|
| 77 |
"Item": item_match.group("Item"),
|
| 78 |
"Description": "",
|
|
@@ -148,20 +149,6 @@ def parse_po_items_with_filters(text):
|
|
| 148 |
df = pd.DataFrame(data)
|
| 149 |
return df, "Data extracted successfully."
|
| 150 |
|
| 151 |
-
# Example text (as provided)
|
| 152 |
-
text = """
|
| 153 |
-
ITEM 1 Stainless Steel RATING AND DIAGRAM PLATE 24 Nos. 3.00 72.00
|
| 154 |
-
As per Drg.No. G 000822 RI RDP 50KVA NT001 51 SIZE : 150mm X 160mm X 1.00mm Thick With Serial No:NT00151 97 to 121 Mfd:-2022
|
| 155 |
-
ITEM 2 Stainless Steel RATING AND DIAGRAM PLATE 12 Nos. 3.80 45.60
|
| 156 |
-
As per Drg.to.G 000816 R2 RDP 600KVA NT00152 SIZE : 150mm X 260mm X 1.00mm Thick With Serial No:NT00I53 38 to 50 Mfd:-2022
|
| 157 |
-
"""
|
| 158 |
-
|
| 159 |
-
# Running the function
|
| 160 |
-
df, status = parse_po_items_with_filters(text)
|
| 161 |
-
print(status)
|
| 162 |
-
if df is not None:
|
| 163 |
-
print(df)
|
| 164 |
-
|
| 165 |
# Function: Save to Excel
|
| 166 |
def save_to_excel(df, output_path="extracted_po_data.xlsx"):
|
| 167 |
"""
|
|
|
|
| 61 |
|
| 62 |
# Match the start of a new item
|
| 63 |
item_match = re.match(r"^(?P<Item>\d+)\s+(?P<Description>.+)", line)
|
| 64 |
+
|
| 65 |
if item_match:
|
| 66 |
print(f"Item match found: {item_match.group('Item')}") # Debugging
|
| 67 |
|
|
|
|
| 73 |
description_accumulator = [] # Reset description accumulator
|
| 74 |
print(f"Item {current_item['Item']} added to data.") # Debugging
|
| 75 |
|
| 76 |
+
# Initialize the current item as it is the start of a new item
|
| 77 |
current_item = {
|
| 78 |
"Item": item_match.group("Item"),
|
| 79 |
"Description": "",
|
|
|
|
| 149 |
df = pd.DataFrame(data)
|
| 150 |
return df, "Data extracted successfully."
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# Function: Save to Excel
|
| 153 |
def save_to_excel(df, output_path="extracted_po_data.xlsx"):
|
| 154 |
"""
|