diff --git a/smart_service/apis/support.py b/smart_service/apis/support.py index 809f03c..8b9be20 100644 --- a/smart_service/apis/support.py +++ b/smart_service/apis/support.py @@ -1,6 +1,13 @@ import frappe import json import time +import re +import os +from frappe.utils import cstr +site_name = cstr(frappe.local.site) + +base_path = os.path.expanduser( + "~") + "/frappe-bench/sites/" + site_name + "/public" # @frappe.whitelist(allow_guest=1) # def delete_all_publish(): @@ -10,4 +17,51 @@ import time # frappe.db.sql('delete from `tabPublish_Docs`;') # except Exception as e: # return str(e) -# return True \ No newline at end of file +# return True + +def change_star_data(): + count = frappe.db.sql(''' + select count(*) from tabProcedure_Details where content like '%**%'; + ''', as_dict=1) + print(count) + updated_list = [] + error_list = [] + data = frappe.db.sql(''' + select step_name,content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; + ''', as_dict=1) + for v in data: + 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: + pass + return content_file +