Shami96 commited on
Commit
d4200b4
·
verified ·
1 Parent(s): 08e93f5

Update updated_word.py

Browse files
Files changed (1) hide show
  1. updated_word.py +26 -2
updated_word.py CHANGED
@@ -974,8 +974,32 @@ def process_tables(document, flat_json):
974
  for row_idx, row in enumerate(table.rows):
975
  for cell_idx, cell in enumerate(row.cells):
976
  if has_red_text(cell):
977
- cell_replacements = handle_management_summary_fix(cell, flat_json) # Use existing function
978
- summary_replacements += cell_replacements
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
  replacements_made += summary_replacements
980
  continue
981
 
 
974
  for row_idx, row in enumerate(table.rows):
975
  for cell_idx, cell in enumerate(row.cells):
976
  if has_red_text(cell):
977
+ # Try direct matching with the new schema names first
978
+ for mgmt_type in ["Mass Management Summary", "Maintenance Management Summary", "Fatigue Management Summary"]:
979
+ if mgmt_type.lower().replace(" summary", "") in table_text:
980
+ # Look for this standard in the JSON
981
+ if mgmt_type in flat_json:
982
+ mgmt_data = flat_json[mgmt_type]
983
+ if isinstance(mgmt_data, dict):
984
+ # Find matching standard
985
+ for std_key, std_value in mgmt_data.items():
986
+ if isinstance(std_value, list) and len(std_value) > 0:
987
+ # Check if red text matches this standard data
988
+ red_text = "".join(run.text for p in cell.paragraphs for run in p.runs if is_red(run)).strip()
989
+ for item in std_value:
990
+ if len(red_text) > 15 and red_text.lower() in str(item).lower():
991
+ replacement_text = "\n".join(str(i) for i in std_value)
992
+ cell_replacements = replace_red_text_in_cell(cell, replacement_text)
993
+ summary_replacements += cell_replacements
994
+ print(f" ✅ Updated {std_key} with summary data")
995
+ break
996
+ break
997
+
998
+ # Fallback to existing method
999
+ if summary_replacements == 0:
1000
+ cell_replacements = handle_management_summary_fix(cell, flat_json)
1001
+ summary_replacements += cell_replacements
1002
+
1003
  replacements_made += summary_replacements
1004
  continue
1005