Browse Source

Publish Api Fix

master
venkataakhil 1 year ago
parent
commit
8a4eed70e1
  1. 21
      smart_service/apis/publish_api.py

21
smart_service/apis/publish_api.py

@ -8,6 +8,9 @@ import os
from frappe.utils import cstr
from smart_service.apis.app_user_login import input_validation
import time
# from frappe.utils import logger
# frappe.utils.logger.set_log_level("DEBUG")
current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
@ -766,21 +769,27 @@ def old_merge_json_files(old_json_path, new_json_path, out_file_path):
except Exception as e:
return False, frappe.get_traceback()
@frappe.whitelist(allow_guest=1)
def merge_json_files(old_json_path, new_json_path, out_file_path):
try:
# try:
final_data = {"JSON": []}
with open(old_json_path, "r") as json_file:
data_old = json.load(json_file)
# logger.debug('Old Json Path',str(old_json_path))
with open(new_json_path, "r") as json_file1:
data_new = json.load(json_file1)
# logger.debug('New Json Path',str(new_json_path))
for k in data_new["JSON"]:
old_var_key = check_key(k["Variant"]["name"], data_old["JSON"], "Variant")
# logger.debug('Old Variant',str(old_var_key))
if old_var_key is not None and old_var_key >= 0:
var_dict = {}
var_dict["Variant"] = k["Variant"]
# logger.debug("variant dict",str(var_dict["Variant"]))
variant_systems = k["Variant"]["Systems"]
var_dict["Variant"]["Systems"] = data_old["JSON"][old_var_key]["Variant"]["Systems"]
@ -810,7 +819,6 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
else:
var_dict["Variant"]["Systems"].append(i)
time.sleep(0.100)
data_old["JSON"][old_var_key] = var_dict
final_data["JSON"].append(var_dict)
@ -822,15 +830,18 @@ def merge_json_files(old_json_path, new_json_path, out_file_path):
outfile.write(json_object)
return True, out_file_path
except:
return False, frappe.log_error("Merge JSON:",frappe.get_traceback())
# except:
# return False, frappe.log_error("Merge JSON:",frappe.get_traceback())
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":
try:
# logger.debug('Variant check',str(old_data[d]["Variant"]["name"]))
# logger.debug('Variant key check',str(key_name))
if old_data[d]["Variant"]["name"] == key_name:
return d
except:

Loading…
Cancel
Save