From 0a17778e4292598a8823d29f232b0cbfd5a7f774 Mon Sep 17 00:00:00 2001 From: venkataakhil Date: Mon, 24 Apr 2023 12:58:48 +0530 Subject: [PATCH] Replace double starapp exception to json file --- smart_service/apis/master_api.py | 48 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/smart_service/apis/master_api.py b/smart_service/apis/master_api.py index 0c0bdf6..0f5bc9c 100644 --- a/smart_service/apis/master_api.py +++ b/smart_service/apis/master_api.py @@ -486,30 +486,42 @@ def change_star_data(): ''', as_dict=1) print(count) updated_list = [] + error_list = [] data = frappe.db.sql(''' select content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; ''', as_dict=1) for v in data: - result = re.split(r"abcxyz ", v['new_content'], flags=0) - FLAG = 0 - sts = '' - if len(result) > 1: - sts += result[0] - for r in range(1, len(result)): - if FLAG == 0: - sts += '' + result[r] + '' - FLAG = 1 - else: - sts += result[r] - FLAG = 0 - frappe.db.sql( - f'''update tabProcedure_Details set content = '{sts}' where name = '{v['name']}'; ''') - v['new_content'] = sts + try: + result = re.split(r"abcxyz ", v['new_content'], flags=0) + FLAG = 0 + sts = '' + if len(result) > 1: + sts += result[0] + for r in range(1, len(result)): + if FLAG == 0: + sts += '' + result[r] + '' + FLAG = 1 + else: + sts += result[r] + FLAG = 0 + frappe.db.sql( + f'''update tabProcedure_Details set content = '{sts}' where name = '{v['name']}'; ''') + v['new_content'] = sts + except Exception as e: + error_list.append({v['name']: e}) updated_list.append(v) + content_file = base_path + "/files/json_files/content_update.json" + error_file = base_path + "/files/json_files/content_error.json" + + with open(error_file, 'w') as outfile: + try: + outfile.write(json.dumps(error_list)) + except: + pass with open(content_file, 'w') as outfile: try: outfile.write(json.dumps(updated_list)) - except Exception as e: - outfile.write(json.dumps(str(e))) - return content_file \ No newline at end of file + except: + pass + return content_file