Spaces:
Running
Running
Update updated_word.py
Browse files- 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 |
-
#
|
| 642 |
-
|
| 643 |
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
"
|
| 649 |
-
|
| 650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 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
|