Spaces:
Running
Running
Update updated_word.py
Browse files- updated_word.py +128 -37
updated_word.py
CHANGED
|
@@ -638,51 +638,52 @@ 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 |
name_cell.text = new_name
|
| 654 |
replacements_made += 1
|
| 655 |
-
print(f" β
Updated Print Name: '{
|
|
|
|
| 656 |
|
| 657 |
-
#
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
|
|
|
| 662 |
if new_position:
|
| 663 |
position_cell.text = new_position
|
| 664 |
replacements_made += 1
|
| 665 |
-
print(f" β
Updated Position Title: '{
|
| 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
|
|
@@ -773,6 +774,96 @@ def handle_management_summary_fix(cell, flat_json):
|
|
| 773 |
|
| 774 |
return replacements_made
|
| 775 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
def handle_operator_declaration_fix(table, flat_json):
|
| 777 |
"""Handle small Operator/Auditor Declaration tables - SKIP if already processed"""
|
| 778 |
replacements_made = 0
|
|
|
|
| 638 |
|
| 639 |
print(f" π Current values: Name='{name_text}', Position='{position_text}'")
|
| 640 |
|
| 641 |
+
# FORCE UPDATE - try direct fields
|
| 642 |
+
print(f" π§ FORCE updating Print Name")
|
| 643 |
+
name_value = find_matching_json_value("Operator Declaration.Print Name", flat_json)
|
| 644 |
+
if name_value:
|
| 645 |
+
new_name = get_value_as_string(name_value).strip()
|
| 646 |
+
if new_name and "Pty Ltd" not in new_name and "Company" not in new_name and "Farming" not in new_name:
|
| 647 |
+
name_cell.text = new_name # FORCE replace
|
| 648 |
+
replacements_made += 1
|
| 649 |
+
print(f" β
FORCE Updated Print Name: '{name_text}' -> '{new_name}'")
|
| 650 |
|
| 651 |
+
print(f" π§ FORCE updating Position Title")
|
| 652 |
+
position_value = find_matching_json_value("Operator Declaration.Position Title", flat_json)
|
| 653 |
+
if position_value:
|
| 654 |
+
new_position = get_value_as_string(position_value).strip()
|
| 655 |
+
if new_position:
|
| 656 |
+
position_cell.text = new_position # FORCE replace
|
| 657 |
+
replacements_made += 1
|
| 658 |
+
print(f" β
FORCE Updated Position Title: '{position_text}' -> '{new_position}'")
|
| 659 |
+
|
| 660 |
+
# If still no updates, try alternative sources
|
| 661 |
+
if replacements_made == 0:
|
| 662 |
+
print(f" π§ Trying alternative sources...")
|
| 663 |
|
| 664 |
+
# Try Print Name alternatives
|
| 665 |
+
alt_name_sources = ["Print Name"]
|
| 666 |
+
for source in alt_name_sources:
|
| 667 |
+
name_value = find_matching_json_value(source, flat_json)
|
| 668 |
+
if name_value:
|
| 669 |
+
new_name = get_value_as_string(name_value).strip()
|
| 670 |
+
if new_name and "Pty Ltd" not in new_name and "Company" not in new_name and "Farming" not in new_name:
|
| 671 |
name_cell.text = new_name
|
| 672 |
replacements_made += 1
|
| 673 |
+
print(f" β
Updated Print Name (alt): '{new_name}' from {source}")
|
| 674 |
+
break
|
| 675 |
|
| 676 |
+
# Try Position Title alternatives
|
| 677 |
+
alt_position_sources = ["Position Title"]
|
| 678 |
+
for source in alt_position_sources:
|
| 679 |
+
position_value = find_matching_json_value(source, 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 (alt): '{new_position}' from {source}")
|
| 686 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
break
|
| 688 |
|
| 689 |
return replacements_made
|
|
|
|
| 774 |
|
| 775 |
return replacements_made
|
| 776 |
|
| 777 |
+
def fix_operator_declaration_empty_values(table, flat_json):
|
| 778 |
+
"""Fix Operator Declaration table when values are empty or need updating"""
|
| 779 |
+
replacements_made = 0
|
| 780 |
+
|
| 781 |
+
print(f" π― FIX: Operator Declaration empty values processing")
|
| 782 |
+
|
| 783 |
+
# Check if this is an Operator Declaration table
|
| 784 |
+
table_context = ""
|
| 785 |
+
for row in table.rows:
|
| 786 |
+
for cell in row.cells:
|
| 787 |
+
table_context += get_clean_text(cell).lower() + " "
|
| 788 |
+
|
| 789 |
+
if not ("print name" in table_context and "position title" in table_context):
|
| 790 |
+
return 0
|
| 791 |
+
|
| 792 |
+
print(f" β
Confirmed Operator Declaration table")
|
| 793 |
+
|
| 794 |
+
# Find the data row with Print Name and Position Title
|
| 795 |
+
for row_idx, row in enumerate(table.rows):
|
| 796 |
+
if len(row.cells) >= 2:
|
| 797 |
+
cell1_text = get_clean_text(row.cells[0]).strip().lower()
|
| 798 |
+
cell2_text = get_clean_text(row.cells[1]).strip().lower()
|
| 799 |
+
|
| 800 |
+
# Check if this is the header row
|
| 801 |
+
if "print name" in cell1_text and "position" in cell2_text:
|
| 802 |
+
print(f" π Found header row at {row_idx + 1}")
|
| 803 |
+
|
| 804 |
+
# Look for the data row (next row)
|
| 805 |
+
if row_idx + 1 < len(table.rows):
|
| 806 |
+
data_row = table.rows[row_idx + 1]
|
| 807 |
+
if len(data_row.cells) >= 2:
|
| 808 |
+
name_cell = data_row.cells[0]
|
| 809 |
+
position_cell = data_row.cells[1]
|
| 810 |
+
|
| 811 |
+
# Check if cells are empty or have red text
|
| 812 |
+
name_text = get_clean_text(name_cell).strip()
|
| 813 |
+
position_text = get_clean_text(position_cell).strip()
|
| 814 |
+
|
| 815 |
+
print(f" π Current values: Name='{name_text}', Position='{position_text}'")
|
| 816 |
+
|
| 817 |
+
# FORCE UPDATE - try direct fields
|
| 818 |
+
print(f" π§ FORCE updating Print Name")
|
| 819 |
+
name_value = find_matching_json_value("Operator Declaration.Print Name", flat_json)
|
| 820 |
+
if name_value:
|
| 821 |
+
new_name = get_value_as_string(name_value).strip()
|
| 822 |
+
if new_name and "Pty Ltd" not in new_name and "Company" not in new_name and "Farming" not in new_name:
|
| 823 |
+
name_cell.text = new_name # FORCE replace
|
| 824 |
+
replacements_made += 1
|
| 825 |
+
print(f" β
FORCE Updated Print Name: '{name_text}' -> '{new_name}'")
|
| 826 |
+
|
| 827 |
+
print(f" π§ FORCE updating Position Title")
|
| 828 |
+
position_value = find_matching_json_value("Operator Declaration.Position Title", flat_json)
|
| 829 |
+
if position_value:
|
| 830 |
+
new_position = get_value_as_string(position_value).strip()
|
| 831 |
+
if new_position:
|
| 832 |
+
position_cell.text = new_position # FORCE replace
|
| 833 |
+
replacements_made += 1
|
| 834 |
+
print(f" β
FORCE Updated Position Title: '{position_text}' -> '{new_position}'")
|
| 835 |
+
|
| 836 |
+
# If still no updates, try alternative sources
|
| 837 |
+
if replacements_made == 0:
|
| 838 |
+
print(f" π§ Trying alternative sources...")
|
| 839 |
+
|
| 840 |
+
# Try Print Name alternatives
|
| 841 |
+
alt_name_sources = ["Print Name"]
|
| 842 |
+
for source in alt_name_sources:
|
| 843 |
+
name_value = find_matching_json_value(source, flat_json)
|
| 844 |
+
if name_value:
|
| 845 |
+
new_name = get_value_as_string(name_value).strip()
|
| 846 |
+
if new_name and "Pty Ltd" not in new_name and "Company" not in new_name and "Farming" not in new_name:
|
| 847 |
+
name_cell.text = new_name
|
| 848 |
+
replacements_made += 1
|
| 849 |
+
print(f" β
Updated Print Name (alt): '{new_name}' from {source}")
|
| 850 |
+
break
|
| 851 |
+
|
| 852 |
+
# Try Position Title alternatives
|
| 853 |
+
alt_position_sources = ["Position Title"]
|
| 854 |
+
for source in alt_position_sources:
|
| 855 |
+
position_value = find_matching_json_value(source, flat_json)
|
| 856 |
+
if position_value:
|
| 857 |
+
new_position = get_value_as_string(position_value).strip()
|
| 858 |
+
if new_position:
|
| 859 |
+
position_cell.text = new_position
|
| 860 |
+
replacements_made += 1
|
| 861 |
+
print(f" β
Updated Position Title (alt): '{new_position}' from {source}")
|
| 862 |
+
break
|
| 863 |
+
break
|
| 864 |
+
|
| 865 |
+
return replacements_made
|
| 866 |
+
|
| 867 |
def handle_operator_declaration_fix(table, flat_json):
|
| 868 |
"""Handle small Operator/Auditor Declaration tables - SKIP if already processed"""
|
| 869 |
replacements_made = 0
|