dschandra commited on
Commit
de8e07a
·
verified ·
1 Parent(s): fdc0157

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -51,14 +51,14 @@ def parse_po_items_with_filters(text):
51
  # Match the start of a new item
52
  item_match = re.match(r"^(?P<Item>\d+)\s+(?P<Description>.+)", line)
53
  if item_match:
54
- # Save the previous item
55
  if current_item:
 
56
  current_item["Description"] = clean_description(
57
  " ".join(description_accumulator).strip(),
58
  item_number=int(current_item["Item"]),
59
  )
60
  data.append(current_item)
61
- description_accumulator = []
62
 
63
  # Start a new item
64
  current_item = {
@@ -69,7 +69,7 @@ def parse_po_items_with_filters(text):
69
  "Unit Price": "",
70
  "Total Price": "",
71
  }
72
- description_accumulator.append(item_match.group("Description"))
73
  elif current_item:
74
  # Accumulate additional lines for the current item's description
75
  description_accumulator.append(line.strip())
@@ -95,10 +95,10 @@ def parse_po_items_with_filters(text):
95
  item_number=int(current_item["Item"]),
96
  )
97
  data.append(current_item)
98
- description_accumulator = []
99
  current_item = None # Reset for the next item
 
100
 
101
- # Save the last item if not already added
102
  if current_item:
103
  current_item["Description"] = clean_description(
104
  " ".join(description_accumulator).strip(),
@@ -106,7 +106,7 @@ def parse_po_items_with_filters(text):
106
  )
107
  data.append(current_item)
108
 
109
- # Remove invalid rows
110
  data = [row for row in data if row["Description"]]
111
 
112
  # Return data as a DataFrame
 
51
  # Match the start of a new item
52
  item_match = re.match(r"^(?P<Item>\d+)\s+(?P<Description>.+)", line)
53
  if item_match:
54
+ # If current_item is not None, finalize and add the previous item
55
  if current_item:
56
+ # Only update description if there's a valid current_item
57
  current_item["Description"] = clean_description(
58
  " ".join(description_accumulator).strip(),
59
  item_number=int(current_item["Item"]),
60
  )
61
  data.append(current_item)
 
62
 
63
  # Start a new item
64
  current_item = {
 
69
  "Unit Price": "",
70
  "Total Price": "",
71
  }
72
+ description_accumulator = [item_match.group("Description")] # Start accumulating description
73
  elif current_item:
74
  # Accumulate additional lines for the current item's description
75
  description_accumulator.append(line.strip())
 
95
  item_number=int(current_item["Item"]),
96
  )
97
  data.append(current_item)
 
98
  current_item = None # Reset for the next item
99
+ description_accumulator = []
100
 
101
+ # Ensure the last item is added if necessary
102
  if current_item:
103
  current_item["Description"] = clean_description(
104
  " ".join(description_accumulator).strip(),
 
106
  )
107
  data.append(current_item)
108
 
109
+ # Remove invalid rows (e.g., missing descriptions)
110
  data = [row for row in data if row["Description"]]
111
 
112
  # Return data as a DataFrame