From c5357b45d907e2076317a5deb7121df4cb016f52 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Thu, 13 Jul 2023 13:10:12 +0530 Subject: [PATCH] Deactivate account --- smart_service/apis/publish_api.py | 74 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/smart_service/apis/publish_api.py b/smart_service/apis/publish_api.py index 43151f4..f863fb8 100644 --- a/smart_service/apis/publish_api.py +++ b/smart_service/apis/publish_api.py @@ -760,7 +760,7 @@ def old_merge_json_files(old_json_path, new_json_path, out_file_path): }) with open(out_file_path, "w") as outfile: - outfile.write(json.dumps(data_consolidated, indent=4)) + outfile.write(json.dumps(data_consolidated)) return True, out_file_path except Exception as e: @@ -770,57 +770,52 @@ def old_merge_json_files(old_json_path, new_json_path, out_file_path): def merge_json_files(old_json_path, new_json_path, out_file_path): try: final_data = {"JSON": []} - with open(old_json_path, "r") as json_file: + with open(old_json_path, 'r') as json_file: data_old = json.load(json_file) - with open(new_json_path, "r") as json_file1: + with open(new_json_path, 'r') as json_file1: data_new = json.load(json_file1) - for k in data_new["JSON"]: - old_var_key = check_key(k["Variant"]["name"], data_old["JSON"], "Variant") - + for k in data_new['JSON']: + old_var_key = check_key(k['Variant']['name'], data_old['JSON'], "Variant") if old_var_key is not None and old_var_key >= 0: var_dict = {} - var_dict["Variant"] = k["Variant"] - variant_systems = k["Variant"]["Systems"] - var_dict["Variant"]["Systems"] = data_old["JSON"][old_var_key]["Variant"]["Systems"] + var_dict['Variant'] = k['Variant'] + variant_systems = k['Variant']['Systems'] + var_dict['Variant']['Systems'] = data_old['JSON'][old_var_key]['Variant']['Systems'] - if not k["Variant"]["Assets"]: - var_dict["Variant"]["Assets"] = data_old["JSON"][old_var_key]["Variant"]["Assets"] + if not k['Variant']['Assets']: + var_dict['Variant']['Assets'] = data_old['JSON'][old_var_key]['Variant']['Assets'] for i in variant_systems: - old_sys_key = check_key(i["sys_id"], var_dict["Variant"]["Systems"], "System") + + old_sys_key = check_key(i['sys_id'], var_dict['Variant']['Systems'], "System") if old_sys_key is not None and old_sys_key >= 0: - var_dict["Variant"]["Systems"][old_sys_key]["systemdisplayorder"] = i["systemdisplayorder"] - var_dict["Variant"]["Systems"][old_sys_key]["icon_file"] = i["icon_file"] - var_dict["Variant"]["Systems"][old_sys_key]["active_status"] = i["active_status"] - - if i["Assets"]: - var_dict["Variant"]["Systems"][old_sys_key]["Assets"] = i["Assets"] - - for s in i["Subsystems"]: - old_sub_key = check_key(s["sub_systems"], - var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"], - "Sub System") - + var_dict['Variant']['Systems'][old_sys_key]['systemdisplayorder'] = i['systemdisplayorder'] + var_dict['Variant']['Systems'][old_sys_key]['icon_file'] = i['icon_file'] + var_dict['Variant']['Systems'][old_sys_key]['active_status'] = i['active_status'] + if i['Assets']: + var_dict['Variant']['Systems'][old_sys_key]['Assets'] = i['Assets'] + + for s in i['Subsystems']: + old_sub_key = check_key(s['sub_systems'], + var_dict['Variant']['Systems'][old_sys_key]['Subsystems'],"Sub System") if old_sub_key is not None and old_sub_key >= 0: - var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"][old_sub_key] = s + var_dict['Variant']['Systems'][old_sys_key]['Subsystems'][old_sub_key] = s else: - var_dict["Variant"]["Systems"][old_sys_key]["Subsystems"].append(s) + var_dict['Variant']['Systems'][old_sys_key]['Subsystems'].append(s) else: - var_dict["Variant"]["Systems"].append(i) + var_dict['Variant']['Systems'].append(i) - time.sleep(0.100) - data_old["JSON"][old_var_key] = var_dict - final_data["JSON"].append(var_dict) + data_old['JSON'][old_var_key] = var_dict + final_data['JSON'].append(var_dict) else: - data_old["JSON"].append(k) + data_old['JSON'].append(k) - json_object = json.dumps(data_old, indent=4) + json_object = json.dumps(data_old) with open(out_file_path, "w") as outfile: outfile.write(json_object) - return True, out_file_path except: return False, frappe.log_error("Merge JSON:",frappe.get_traceback()) @@ -829,21 +824,24 @@ def check_key(key_name, old_data, type=None): old_file_length = len(old_data) for d in range(0, old_file_length): if type == "Variant": - if old_data[d]["Variant"]["name"] == key_name: - return d - + try: + if old_data[d]["Variant"]["name"] == key_name: + return d + except: + frappe.log_error("Check key System:",frappe.get_traceback()) + if type == "System": try: if old_data[d]["sys_id"] == key_name: return d - except Exception as e: + except: frappe.log_error("Check key System:",frappe.get_traceback()) if type == "Sub System": try: if old_data[d]["sub_systems"] == key_name: return d - except Exception as e2: + except: frappe.log_error("Check key subsystem:",frappe.get_traceback())