Shami96 commited on
Commit
f144bc7
Β·
verified Β·
1 Parent(s): e95e088

Update updated_word.py

Browse files
Files changed (1) hide show
  1. updated_word.py +43 -69
updated_word.py CHANGED
@@ -638,77 +638,51 @@ def fix_operator_declaration_empty_values(table, flat_json):
638
 
639
  print(f" πŸ“‹ Current values: Name='{name_text}', Position='{position_text}'")
640
 
641
- # ALWAYS update Print Name with new data - check for red text OR existing data
642
- print(f" πŸ”§ Updating Print Name")
643
 
644
- # Try multiple sources for operator name
645
- name_sources = [
646
- "Operator Declaration.Print Name",
647
- "Print Name",
648
- "Operator name (Legal entity)",
649
- "(print accreditation name)"
650
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
 
652
- for source in name_sources:
653
- name_value = find_matching_json_value(source, flat_json)
654
- if name_value is not None:
655
- name_replacement = get_value_as_string(name_value)
656
- if name_replacement.strip():
657
- # Extract just the name if it's a company name
658
- if "Pty Ltd" in name_replacement or "Company" in name_replacement:
659
- continue
660
-
661
- # Check if we need to update (different from current)
662
- if name_replacement.strip() != name_text:
663
- if has_red_text(name_cell):
664
- cell_replacements = replace_red_text_in_cell(name_cell, name_replacement)
665
- else:
666
- # Replace existing text
667
- name_cell.text = name_replacement
668
- cell_replacements = 1
669
-
670
- replacements_made += cell_replacements
671
- print(f" βœ… Updated Print Name: '{name_text}' -> '{name_replacement}' (from {source})")
672
- break
673
- else:
674
- print(f" ℹ️ Print Name already correct: '{name_replacement}'")
675
- break
676
-
677
- # ALWAYS update Position Title with new data
678
- print(f" πŸ”§ Updating Position Title")
679
-
680
- position_sources = [
681
- "Operator Declaration.Position Title",
682
- "Position Title"
683
- ]
684
-
685
- for source in position_sources:
686
- position_value = find_matching_json_value(source, flat_json)
687
- if position_value is not None:
688
- position_replacement = get_value_as_string(position_value)
689
- if position_replacement.strip():
690
-
691
- # Check if we need to update (different from current)
692
- if position_replacement.strip() != position_text:
693
- if has_red_text(position_cell):
694
- cell_replacements = replace_red_text_in_cell(position_cell, position_replacement)
695
- else:
696
- # Replace existing text
697
- position_cell.text = position_replacement
698
- cell_replacements = 1
699
-
700
- replacements_made += cell_replacements
701
- print(f" βœ… Updated Position Title: '{position_text}' -> '{position_replacement}' (from {source})")
702
- break
703
- else:
704
- print(f" ℹ️ Position Title already correct: '{position_replacement}'")
705
- break
706
-
707
- # Fallback: use "Manager" if nothing found and cell is empty
708
- if not position_text and not has_red_text(position_cell):
709
- position_cell.text = "Manager"
710
- replacements_made += 1
711
- print(f" βœ… Used fallback Position Title: 'Manager'")
712
  break
713
 
714
  return replacements_made
 
638
 
639
  print(f" πŸ“‹ Current values: Name='{name_text}', Position='{position_text}'")
640
 
641
+ # Get the Operator Declaration section data
642
+ operator_declaration = find_matching_json_value("Operator Declaration", flat_json)
643
 
644
+ if operator_declaration and isinstance(operator_declaration, dict):
645
+ print(f" πŸ” Found Operator Declaration data: {operator_declaration}")
646
+
647
+ # Update Print Name
648
+ if "Print Name" in operator_declaration:
649
+ print_name_value = operator_declaration["Print Name"]
650
+ if isinstance(print_name_value, list) and print_name_value:
651
+ new_name = str(print_name_value[0]).strip()
652
+ if new_name and "Pty Ltd" not in new_name and "Company" not in new_name:
653
+ name_cell.text = new_name
654
+ replacements_made += 1
655
+ print(f" βœ… Updated Print Name: '{name_text}' -> '{new_name}'")
656
+
657
+ # Update Position Title
658
+ if "Position Title" in operator_declaration:
659
+ position_value = operator_declaration["Position Title"]
660
+ if isinstance(position_value, list) and position_value:
661
+ new_position = str(position_value[0]).strip()
662
+ if new_position:
663
+ position_cell.text = new_position
664
+ replacements_made += 1
665
+ print(f" βœ… Updated Position Title: '{position_text}' -> '{new_position}'")
666
 
667
+ else:
668
+ print(f" ❌ No Operator Declaration section found in JSON")
669
+
670
+ # Fallback: try individual fields
671
+ name_value = find_matching_json_value("Operator Declaration.Print Name", flat_json)
672
+ if name_value:
673
+ new_name = get_value_as_string(name_value).strip()
674
+ if new_name and "Pty Ltd" not in new_name:
675
+ name_cell.text = new_name
676
+ replacements_made += 1
677
+ print(f" βœ… Updated Print Name (fallback): '{new_name}'")
678
+
679
+ position_value = find_matching_json_value("Operator Declaration.Position Title", flat_json)
680
+ if position_value:
681
+ new_position = get_value_as_string(position_value).strip()
682
+ if new_position:
683
+ position_cell.text = new_position
684
+ replacements_made += 1
685
+ print(f" βœ… Updated Position Title (fallback): '{new_position}'")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
  break
687
 
688
  return replacements_made