Browse Source

Change Unordered star data

master
venkataakhil 1 year ago
parent
commit
7a7947d9b9
  1. 82
      smart_service/apis/master_api.py

82
smart_service/apis/master_api.py

@ -529,49 +529,41 @@ def change_star_data():
def change_single_star_data():
count = frappe.db.sql('''
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1)
select count(*) from tabProcedure_Details where content like "%* %";''', as_dict=1)
print(count)
# updated_list = []
# error_list = []
# data = frappe.db.sql('''
# select parent,step_name,content_type,content,name,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)
# sts = '<ul>'
# if result[0] == '' and len(result) > 2:
# for a in range(1, len(result)):
# sts += '<li>' + result[a] + '</li> '
# sts += '</ul>'
# # print(sts)
# else:
# sts += '<li>' + result[1] + '</li> '
# sts += '</ul>'
# # print(sts)
# frappe.db.sql(
# f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''')
# frappe.db.commit()
# v['new_content'] = sts
# updated_list.append(v)
# except Exception as e:
# error_list.append({v['name']: e})
# content_file = base_path + "/files/json_files/content_single_star_update.json"
# error_file = base_path + "/files/json_files/content_error_single_star.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
updated_list = []
error_list = []
data = frappe.db.sql('''
select name,parent,step_name,content_type,content,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)
sts = '<ul>'
if len(result) > 1:
for a in range(1, len(result)):
sts += '<li>' + result[a] + '</li> '
sts += '</ul>'
frappe.db.sql(
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''')
frappe.db.commit()
v['new_content'] = sts
updated_list.append(v)
except Exception as e:
error_list.append({v['name']: e})
content_file = base_path + "/files/json_files/content_single_star_update.json"
error_file = base_path + "/files/json_files/content_error_single_star.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

Loading…
Cancel
Save