import json import math def modify_json_values(json_file): # Constant definitions WeichenKoerperWidth = 32.5437 BogenProfileWidth = 42.080 WeichenkProfileWidth = 42.000 WeichenGerade = 360.000 # Read JSON file with open(json_file, 'r', encoding='utf-8') as f: data = json.load(f) process_einzelweiche_items(data,WeichenKoerperWidth, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade) process_doppelweiche_items(data, BogenProfileWidth, WeichenGerade) process_dreifachweiche_items(data, WeichenkProfileWidth) # Ask for save confirmation save_choice = input("\nSave all changes? (Press Enter to save, 'n' to cancel): ").lower() if save_choice == 'n': print("All changes discarded") else: with open(json_file, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, ensure_ascii=False) print("All changes saved!") def process_einzelweiche_items(data,WeichenKoerperWidth, WeichenkProfileWidth,BogenProfileWidth, WeichenGerade): # Filter matching items filtered_items = [ item for item in data if (item.get("SivasnrTEF") is None and item.get("KurvenRichtung") == 1 and item.get("Schaltungstyp") == "M") ] print(f"Found {len(filtered_items)} matching records") print("="*50) # Process each item for idx, item in enumerate(filtered_items, 1): print(f"\nItem {idx}:") print(f"Sivasnr: {item['Sivasnr']}") print(f"ProfilTyp: {item['ProfilTyp']}") print(f"Schaltungstyp: {item['Schaltungstyp']}") # Process OFWeiche_center_line_width_mm current_value = item.get("OFWeiche_center_line_width_mm") print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_width_mm"] item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}") except ValueError: print("Invalid input, keeping original value") else: print("Skipping modification") # Process OFWeiche_center_line_height_mm current_value = item.get("OFWeiche_center_line_height_mm") print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_height_mm"] item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}") except ValueError: print("Invalid input, keeping original value") else: print("Skipping modification") # Calculate related values if (item["OFWeiche_center_line_width_mm"] is not None and item["OFWeiche_center_line_height_mm"] is not None): angle_rad = math.radians(item["KurvenWinkel"]) # Calculate and print basic values old_width = item.get("Objekte_width_mm") item["Objekte_width_mm"] = round(WeichenKoerperWidth+ (BogenProfileWidth/2 * math.cos(angle_rad)) + item["OFWeiche_center_line_width_mm"] + WeichenkProfileWidth/2, 3) print(f"\nObjekte_width_mm calculated update: {old_width} → {item['Objekte_width_mm']}") old_height = item.get("Objekte_height_mm") if item["KurvenWinkel"] == 22.5: item["Objekte_height_mm"] = round( item["OFWeiche_center_line_height_mm"], 3) else: item["Objekte_height_mm"] = round( (BogenProfileWidth/2 * math.sin(angle_rad)) + item["OFWeiche_center_line_height_mm"], 3) print(f"Objekte_height_mm calculated update: {old_height} → {item['Objekte_height_mm']}") # Calculate and print CP point coordinates old_cp1x = item.get("OFWeiche_CP1_x_mm") item["OFWeiche_CP1_x_mm"] = round( (BogenProfileWidth/2 * math.sin(angle_rad)) + item["OFWeiche_center_line_width_mm"], 3) print(f"OFWeiche_CP1_x_mm calculated update: {old_cp1x} → {item['OFWeiche_CP1_x_mm']}") old_cp1y = item.get("OFWeiche_CP1_y_mm") item["OFWeiche_CP1_y_mm"] = round( item["Objekte_height_mm"] - WeichenGerade, 3) print(f"OFWeiche_CP1_y_mm calculated update: {old_cp1y} → {item['OFWeiche_CP1_y_mm']}") item["OFWeiche_CP2_x_mm"] = round(item["OFWeiche_CP1_x_mm"], 3) print(f"OFWeiche_CP2_x_mm set: {item['OFWeiche_CP2_x_mm']}") item["OFWeiche_CP2_y_mm"] = round(item["Objekte_height_mm"], 3) print(f"OFWeiche_CP2_y_mm set: {item['OFWeiche_CP2_y_mm']}") item["OFWeiche_CP3_x_mm"] = round( BogenProfileWidth/2 * math.cos(angle_rad), 3) print(f"OFWeiche_CP3_x_mm calculated update: {item['OFWeiche_CP3_x_mm']}") item["OFWeiche_CP3_y_mm"] = round( BogenProfileWidth/2 * math.sin(angle_rad), 3) print(f"OFWeiche_CP3_y_mm calculated update: {item['OFWeiche_CP3_y_mm']}") # 1. Find similar items with Schaltungstyp=P (update all CP points) current_profil = item["ProfilTyp"] if "S" in current_profil: prefix = current_profil.rsplit(" ", 1)[0] similar_items_p = [x for x in data if x["ProfilTyp"].startswith(prefix) and x["ProfilTyp"] != current_profil and "WEICHE" in x["ProfilTyp"] and x.get("SivasnrTEF") is None and x.get("Schaltungstyp") == "P"] if similar_items_p: print(f"\nFound {len(similar_items_p)} similar items with Schaltungstyp=P") for similar in similar_items_p: print(f"Updating similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})") # Update all fields including CP points fields_to_copy = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm" ] for field in fields_to_copy: old_val = similar.get(field) similar[field] = item[field] print(f" {field}: {old_val} → {similar[field]}") else: print("No similar items with Schaltungstyp=P found") # 2. Find L→R similar items with KurvenRichtung=2 if "S" in current_profil and "-L-" in current_profil: r_profil = current_profil.replace("-L-", "-R-") similar_items_r = [x for x in data if x["ProfilTyp"] == r_profil and x.get("SivasnrTEF") is None and x.get("KurvenRichtung") == 2 and x.get("Schaltungstyp") == "M"] if similar_items_r: print(f"\nFound {len(similar_items_r)} L→R similar items (KurvenRichtung=2)") for similar in similar_items_r: print(f"Updating R-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})") # Copy basic values base_fields = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm" ] for field in base_fields: old_val = similar.get(field) similar[field] = item[field] print(f" {field}: {old_val} → {similar[field]}") # Calculate and print R-type specific CP points old_cp1x = similar.get("OFWeiche_CP1_x_mm") similar["OFWeiche_CP1_x_mm"] = round(WeichenKoerperWidth+WeichenkProfileWidth/2, 3) print(f" OFWeiche_CP1_x_mm (R-type): {old_cp1x} → {similar['OFWeiche_CP1_x_mm']}") old_cp1y = similar.get("OFWeiche_CP1_y_mm") similar["OFWeiche_CP1_y_mm"] = round(item["Objekte_height_mm"] - WeichenGerade, 3) print(f" OFWeiche_CP1_y_mm (R-type): {old_cp1y} → {similar['OFWeiche_CP1_y_mm']}") similar["OFWeiche_CP2_x_mm"] = similar["OFWeiche_CP1_x_mm"] print(f" OFWeiche_CP2_x_mm (R-type): Set to {similar['OFWeiche_CP2_x_mm']}") old_cp2y = similar.get("OFWeiche_CP2_y_mm") similar["OFWeiche_CP2_y_mm"] = round(item["Objekte_height_mm"], 3) print(f" OFWeiche_CP2_y_mm (R-type): {old_cp2y} → {similar['OFWeiche_CP2_y_mm']}") old_cp3x = similar.get("OFWeiche_CP3_x_mm") similar["OFWeiche_CP3_x_mm"] = round( similar["OFWeiche_CP1_x_mm"] + item["OFWeiche_center_line_width_mm"], 3) print(f" OFWeiche_CP3_x_mm (R-type): {old_cp3x} → {similar['OFWeiche_CP3_x_mm']}") old_cp3y = similar.get("OFWeiche_CP3_y_mm") similar["OFWeiche_CP3_y_mm"] = round( BogenProfileWidth/2 * math.sin(angle_rad), 3) print(f" OFWeiche_CP3_y_mm (R-type): {old_cp3y} → {similar['OFWeiche_CP3_y_mm']}") # 3. Find P-type counterparts for this R-type item r_p_profil = r_profil.replace("MIT M", "MIT P") similar_items_r_p = [x for x in data if x["ProfilTyp"] == r_p_profil and x.get("SivasnrTEF") is None and x.get("Schaltungstyp") == "P"] if similar_items_r_p: print(f"\nFound {len(similar_items_r_p)} R-type P-type counterparts") for similar_r_p in similar_items_r_p: print(f"Updating R-type P-type counterpart: {similar_r_p['ProfilTyp']} (Sivasnr: {similar_r_p['Sivasnr']})") fields_to_copy_r_p = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm" ] for field in fields_to_copy_r_p: old_val = similar_r_p.get(field) similar_r_p[field] = similar[field] print(f" {field}: {old_val} → {similar_r_p[field]}") save_choice = input(f"Confirm update for this item? (Enter to confirm, 'n' to cancel): ").lower() if save_choice == 'n': print("Update for this item cancelled") # Restore original values for field in fields_to_copy_r_p: if field in similar_r_p: similar_r_p[field] = old_val else: print("No R-type P-type counterparts found") else: print("No L→R similar items found") def process_doppelweiche_items(data,BogenProfileWidth, WeichenGerade): # Filter Doppelweiche type items filtered_items = [ item for item in data if (item.get("WeichenTyp") == "Doppelweiche" and item.get("Schaltungstyp") == "M" and item.get("SivasnrTEF") is None) ] print(f"\n\nFound {len(filtered_items)} Doppelweiche type records") print("="*50) # Process each Doppelweiche item for idx, item in enumerate(filtered_items, 1): print(f"\nDoppelweiche item {idx}:") print(f"Sivasnr: {item['Sivasnr']}") print(f"ProfilTyp: {item['ProfilTyp']}") print(f"Schaltungstyp: {item['Schaltungstyp']}") print(f"KurvenWinkel: {item['KurvenWinkel']}") # Process OFWeiche_center_line_width_mm current_value = item.get("OFWeiche_center_line_width_mm") print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_width_mm"] item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}") except ValueError: print("Invalid input, keeping original value") else: print("Skipping modification") # Process OFWeiche_center_line_height_mm current_value = item.get("OFWeiche_center_line_height_mm") print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_height_mm"] item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}") except ValueError: print("Invalid input, keeping original value") else: print("Skipping modification") # Calculate related values if (item["OFWeiche_center_line_width_mm"] is not None and item["OFWeiche_center_line_height_mm"] is not None): angle_rad = math.radians(item["KurvenWinkel"]) # Calculate and print basic values (Doppelweiche specific formula) old_width = item.get("Objekte_width_mm") item["Objekte_width_mm"] = round( (BogenProfileWidth/2 * math.cos(angle_rad)) + item["OFWeiche_center_line_width_mm"] + BogenProfileWidth/2 * math.cos(angle_rad), 3) print(f"\nObjekte_width_mm calculated update: {old_width} → {item['Objekte_width_mm']}") old_height = item.get("Objekte_height_mm") item["Objekte_height_mm"] = round( (BogenProfileWidth/2 * math.sin(angle_rad)) + item["OFWeiche_center_line_height_mm"], 3) print(f"Objekte_height_mm calculated update: {old_height} → {item['Objekte_height_mm']}") # Calculate and print CP point coordinates (Doppelweiche specific formula) item["OFWeiche_CP1_x_mm"] = round(item["Objekte_width_mm"]/2, 3) print(f"OFWeiche_CP1_x_mm calculated update: {item['OFWeiche_CP1_x_mm']}") item["OFWeiche_CP1_y_mm"] = round(item["Objekte_height_mm"], 3) print(f"OFWeiche_CP1_y_mm calculated update: {item['OFWeiche_CP1_y_mm']}") item["OFWeiche_CP2_x_mm"] = round(BogenProfileWidth/2 * math.cos(angle_rad), 3) print(f"OFWeiche_CP2_x_mm calculated update: {item['OFWeiche_CP2_x_mm']}") item["OFWeiche_CP2_y_mm"] = round(BogenProfileWidth/2 * math.sin(angle_rad), 3) print(f"OFWeiche_CP2_y_mm calculated update: {item['OFWeiche_CP2_y_mm']}") item["OFWeiche_CP3_x_mm"] = round( BogenProfileWidth/2 * math.cos(angle_rad) + item["OFWeiche_center_line_width_mm"], 3) print(f"OFWeiche_CP3_x_mm calculated update: {item['OFWeiche_CP3_x_mm']}") item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"] print(f"OFWeiche_CP3_y_mm set: {item['OFWeiche_CP3_y_mm']}") # 1. Find similar items (D-type P-type) current_profil = item["ProfilTyp"] if "S D" in current_profil: d_p_profil = current_profil.replace("MIT M", "MIT P") similar_items_d_p = [x for x in data if x["ProfilTyp"] == d_p_profil and x.get("SivasnrTEF") is None] if similar_items_d_p: print(f"\nFound {len(similar_items_d_p)} D-type P-type similar items") for similar in similar_items_d_p: print(f"Updating D-type P-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})") # Update all fields fields_to_copy = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm" ] for field in fields_to_copy: old_val = similar.get(field) similar[field] = item[field] print(f" {field}: {old_val} → {similar[field]}") else: print("No D-type P-type similar items found") # 2. Find similar items (T-type M-type) if "S D" in current_profil: t_m_profil = current_profil.replace("S D", "S T") similar_items_t_m = [x for x in data if x["ProfilTyp"] == t_m_profil and x.get("SivasnrTEF") is None and x.get("Schaltungstyp") == "M"] if similar_items_t_m: print(f"\nFound {len(similar_items_t_m)} T-type M-type similar items") for similar in similar_items_t_m: print(f"Updating T-type M-type similar item: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})") if similar["KurvenWinkel"] == 22.5: print("Detected KurvenWinkel=22.5, applying special handling") # Special handling logic similar["OFWeiche_center_line_width_mm"] = item["OFWeiche_center_line_width_mm"] print(f" OFWeiche_center_line_width_mm: → {similar['OFWeiche_center_line_width_mm']}") similar["OFWeiche_center_line_height_mm"] = WeichenGerade print(f" OFWeiche_center_line_height_mm: → {WeichenGerade}") similar["Objekte_width_mm"] = item["Objekte_width_mm"] print(f" Objekte_width_mm: → {similar['Objekte_width_mm']}") similar["Objekte_height_mm"] = WeichenGerade print(f" Objekte_height_mm: → {WeichenGerade}") similar["OFWeiche_CP1_x_mm"] = item["OFWeiche_CP1_x_mm"] print(f" OFWeiche_CP1_x_mm: → {similar['OFWeiche_CP1_x_mm']}") similar["OFWeiche_CP1_y_mm"] = similar["Objekte_height_mm"] print(f" OFWeiche_CP1_y_mm: → {similar['OFWeiche_CP1_y_mm']}") similar["OFWeiche_CP2_x_mm"] = item["OFWeiche_CP2_x_mm"] print(f" OFWeiche_CP2_x_mm: → {similar['OFWeiche_CP2_x_mm']}") similar["OFWeiche_CP2_y_mm"] = 20 print(f" OFWeiche_CP2_y_mm: → 20") similar["OFWeiche_CP3_x_mm"] = item["OFWeiche_CP3_x_mm"] print(f" OFWeiche_CP3_x_mm: → {similar['OFWeiche_CP3_x_mm']}") similar["OFWeiche_CP3_y_mm"] = 20 print(f" OFWeiche_CP3_y_mm: → 20") else: # Update basic fields base_fields = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm" ] for field in base_fields: old_val = similar.get(field) similar[field] = item[field] print(f" {field}: {old_val} → {similar[field]}") # Add CP4 point (T-type specific) similar["OFWeiche_CP4_x_mm"] = round(item["Objekte_width_mm"]/2, 3) print(f" OFWeiche_CP4_x_mm added: {similar['OFWeiche_CP4_x_mm']}") similar["OFWeiche_CP4_y_mm"] = round(item["Objekte_height_mm"] - WeichenGerade, 3) print(f" OFWeiche_CP4_y_mm added: {similar['OFWeiche_CP4_y_mm']}") # 3. Find T-type P-type counterparts t_p_profil = t_m_profil.replace("MIT M", "MIT P") similar_items_t_p = [x for x in data if x["ProfilTyp"] == t_p_profil and x.get("SivasnrTEF") is None and x.get("Schaltungstyp") == "P"] if similar_items_t_p: print(f"\nFound {len(similar_items_t_p)} T-type P-type counterparts") for similar_t_p in similar_items_t_p: print(f"Updating T-type P-type counterpart: {similar_t_p['ProfilTyp']} (Sivasnr: {similar_t_p['Sivasnr']})") # Update all fields including CP4 point fields_to_copy_t_p = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm", "OFWeiche_CP4_x_mm", "OFWeiche_CP4_y_mm" ] for field in fields_to_copy_t_p: old_val = similar_t_p.get(field) similar_t_p[field] = similar[field] print(f" {field}: {old_val} → {similar_t_p[field]}") # Add save confirmation prompt save_choice = input(f"Confirm update for this item? (Enter to confirm, 'n' to cancel): ").lower() if save_choice == 'n': print("Update for this item cancelled") # Restore original values for field in fields_to_copy_t_p: similar_t_p[field] = old_val else: print("No T-type P-type counterparts found") else: print("No T-type M-type similar items found") def process_dreifachweiche_items(data, WeichenkProfileWidth): # Filter Dreifachweiche type items filtered_items = [ item for item in data if (item.get("WeichenTyp") == "Dreifachweiche" and item.get("Schaltungstyp") == "M" and item.get("SivasnrTEF") is None) ] print(f"\n\nFound {len(filtered_items)} Dreifachweiche type records") print("="*50) for idx, item in enumerate(filtered_items, 1): print(f"\nDreifachweiche item {idx}:") print(f"Sivasnr: {item['Sivasnr']}") print(f"ProfilTyp: {item['ProfilTyp']}") # Interactive modification of OFWeiche_center_line_width_mm current_value = item.get("OFWeiche_center_line_width_mm") print(f"\nCurrent OFWeiche_center_line_width_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_width_mm"] item["OFWeiche_center_line_width_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_width_mm']}") except ValueError: print("Invalid input, keeping original value") # Interactive modification of OFWeiche_center_line_height_mm current_value = item.get("OFWeiche_center_line_height_mm") print(f"\nCurrent OFWeiche_center_line_height_mm: {current_value}") choice = input("Modify? (y to modify, Enter to skip): ").lower() if choice == 'y': new_value = input(f"Enter new value (current: {current_value}): ") try: old_value = item["OFWeiche_center_line_height_mm"] item["OFWeiche_center_line_height_mm"] = round(float(new_value), 3) if new_value.lower() != 'null' else None print(f"Value updated: {old_value} → {item['OFWeiche_center_line_height_mm']}") except ValueError: print("Invalid input, keeping original value") # Calculate related values if (item["OFWeiche_center_line_width_mm"] is not None and item["OFWeiche_center_line_height_mm"] is not None): # Calculate basic dimensions item["Objekte_width_mm"] = round(item["OFWeiche_center_line_width_mm"], 3) print(f"\nObjekte_width_mm calculated update: {item['Objekte_width_mm']}") item["Objekte_height_mm"] = round(WeichenkProfileWidth/2 + item["OFWeiche_center_line_height_mm"], 3) print(f"Objekte_height_mm calculated update: {item['Objekte_height_mm']}") # Calculate control points item["OFWeiche_CP1_x_mm"] = round(item["Objekte_width_mm"]/2, 3) item["OFWeiche_CP1_y_mm"] = 0 item["OFWeiche_CP2_x_mm"] = 0 item["OFWeiche_CP2_y_mm"] = round(item["OFWeiche_center_line_height_mm"], 3) item["OFWeiche_CP3_x_mm"] = round(item["OFWeiche_center_line_width_mm"], 3) item["OFWeiche_CP3_y_mm"] = item["OFWeiche_CP2_y_mm"] print(f"OFWeiche_CP1_x_mm: {item['OFWeiche_CP1_x_mm']}") print(f"OFWeiche_CP1_y_mm: {item['OFWeiche_CP1_y_mm']}") print(f"OFWeiche_CP2_x_mm: {item['OFWeiche_CP2_x_mm']}") print(f"OFWeiche_CP2_y_mm: {item['OFWeiche_CP2_y_mm']}") print(f"OFWeiche_CP3_x_mm: {item['OFWeiche_CP3_x_mm']}") print(f"OFWeiche_CP3_y_mm: {item['OFWeiche_CP3_y_mm']}") # Find similar items (P-type) if "WEICHE S C DELTA" in item["ProfilTyp"]: similar_profil = item["ProfilTyp"].replace("KPL. M", "KPL. P") similar_items = [x for x in data if x["ProfilTyp"] == similar_profil and x.get("SivasnrTEF") is None] if similar_items: print(f"\nFound {len(similar_items)} similar P-type items") for similar in similar_items: print(f"\nUpdating: {similar['ProfilTyp']} (Sivasnr: {similar['Sivasnr']})") fields_to_copy = [ "OFWeiche_center_line_width_mm", "OFWeiche_center_line_height_mm", "Objekte_width_mm", "Objekte_height_mm", "OFWeiche_CP1_x_mm", "OFWeiche_CP1_y_mm", "OFWeiche_CP2_x_mm", "OFWeiche_CP2_y_mm", "OFWeiche_CP3_x_mm", "OFWeiche_CP3_y_mm" ] print("\nUpdating:") for field in fields_to_copy: print(f" {field}: {similar.get(field)} → {item[field]}") similar[field] = item[field] # Actually update the similar item's value choice = input("\nConfirm update for this item? (Enter to confirm/n to cancel): ").lower() if choice == 'n': print("Update for this item cancelled") for field in fields_to_copy: similar[field] = similar[field] else: print("Update for this item confirmed") else: print("No similar P-type items found") if __name__ == "__main__": json_file_path = "omniflo_weichen.json" # Replace with your JSON file path modify_json_values(json_file_path)