How to use dump_json method in lisa

Best Python code snippet using lisa_python

api_data.py

Source:api_data.py Github

copy

Full Screen

...79 ('name_kanji', data['name']),80 ]) for reading, data in readings.items()]81def CJK_compatibility(character):82 return u'\uF900' <= literal(character) <= u'\uFAFF'83def dump_json(filename, obj):84 with open(filename, 'w', encoding='utf8') as f:85 ujson.dump(obj, f, ensure_ascii=False)86def main():87 VERSION_PATH = 'v1'88 SITE_PATH = f'out/site'89 OUT_PATH = f'out/{VERSION_PATH}'90 KANJI_DIR = f'{OUT_PATH}/kanji/'91 WORD_DIR = f'{OUT_PATH}/words/'92 READING_DIR = f'{OUT_PATH}/reading/'93 JOUYOU_GRADES = [1, 2, 3, 4, 5, 6, 8]94 JINMEIYOU_GRADES = [9, 10]95 kanjidic_root = etree.parse('kanjidic2.xml')96 jmdict_entries = etree.parse('JMDict').xpath('//entry')97 characters = kanjidic_root.xpath('./character')98 kanji_to_entries = word_dict(jmdict_entries)99 kanjis = [100 kanji_data(character)101 for character in characters102 if not CJK_compatibility(character)103 ]104 readings = reading_data(kanjis)105 all_kanji = [kanji['kanji'] for kanji in kanjis]106 words = {}107 for kanji in kanjis:108 dump_json(KANJI_DIR + kanji['kanji'], kanji)109 try:110 entries = tuple(kanji_to_entries[kanji['kanji']])111 dump_json(WORD_DIR + kanji['kanji'], entries)112 words[kanji['kanji']] = entries113 except KeyError:114 continue115 for reading in readings:116 dump_json(READING_DIR + reading['reading'], reading)117 jouyou_kanji = [118 kanji['kanji']119 for kanji in kanjis120 if kanji['grade'] in JOUYOU_GRADES121 ]122 jinmeiyou_kanji = [123 kanji['kanji']124 for kanji in kanjis125 if kanji['grade'] in JINMEIYOU_GRADES126 ]127 dump_json(KANJI_DIR + 'all', all_kanji)128 dump_json(KANJI_DIR + 'jouyou', jouyou_kanji)129 dump_json(KANJI_DIR + 'joyo', jouyou_kanji)130 dump_json(KANJI_DIR + 'jinmeiyou', jinmeiyou_kanji)131 dump_json(KANJI_DIR + 'jinmeiyo', jinmeiyou_kanji)132 with ZipFile(f'{SITE_PATH}/kanjiapi_full.zip', 'w', compression=ZIP_DEFLATED) as archive:133 api_data_download = {134 'kanjis': {kanji['kanji']: kanji for kanji in kanjis},135 'readings': {reading['reading']: reading for reading in readings},136 'words': words,137 }138 json_filename = f'{SITE_PATH}/kanjiapi_full.json'139 dump_json(json_filename, api_data_download)140 archive.write(json_filename, arcname='kanjiapi_full.json')141 os.remove(json_filename)142 for grade_numeral in JOUYOU_GRADES:143 grade_kanji = [144 kanji['kanji']145 for kanji in kanjis146 if kanji['grade'] == grade_numeral147 ]...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...10def index(request):11 return render(request, "api-index.html")12def malaria(request):13 if not validate_API(request.GET.get("key", "~~~")):14 return HttpResponse(dump_json({"success": False, "error": "Invalid Creds", "test_type": "malaria", "message": None}))15 try:16 img_url = request.GET.get("img_url", None)17 if img_url:18 img_data = get_image_data(img_url)19 img_data = preprocess_malaria(img_data)20 test_result = malaria_model.predict([[img_data]])21 confidence_score = test_result[0][test_result.argmax()] * 10022 if test_result.argmax() == 0:23 test_message = "Malaria Negative with {:.2f}% confidence".format(confidence_score)24 result = "Negative"25 else:26 test_message = "Malaria Positive with {:.2f}% confidence".format(confidence_score)27 result = "Positive"28 else:29 return HttpResponse(dump_json({"success": False, "test_type": "malaria", "error": "No image url was provided", "message": None}))30 return HttpResponse(dump_json({"success": True, "error": None, "test_type": "malaria", "message": test_message, "result": result, "confidence": confidence_score}))31 except Exception as e:32 return HttpResponse(dump_json({"success": False, "error": "An error occured during the test", "test_type": "malaria", "message": None}))33def skin_cancer(request):34 if not validate_API(request.GET.get("key", "~~~")):35 return HttpResponse(dump_json({"success": False, "error": "Invalid Creds", "test_type": "skin_cancer", "message": None}))36 try:37 img_url = request.GET.get("img_url", None)38 if img_url:39 img_data = get_image_data(img_url)40 img_data = preprocess_skin_cancer(img_data)41 test_result = skin_cancer_model.predict([[img_data]])[0][0]42 if round(test_result) == 0:43 confidence_score = (1 - test_result) * 10044 test_message = "Detected Benign Cancer with {:.2f}% confidence".format(confidence_score)45 result = "Benign"46 else:47 confidence_score = test_result * 10048 test_message = "Detected Malignant Cancer with {:.2f}% confidence".format(confidence_score)49 result = "Malignant"50 else:51 return HttpResponse(dump_json({"success": False, "test_type": "skin_cancer", "error": "No image url was provided", "message": None}))52 return HttpResponse(dump_json({"success": True, "error": None, "test_type": "skin_cancer", "message": test_message, "result": result, "confidence": confidence_score}))53 except Exception as e:...

Full Screen

Full Screen

correct_exp.py

Source:correct_exp.py Github

copy

Full Screen

1import json, re2import os, sys3dump_list = []4dump_json = {}5uid = 06name = ""7f1= open("dev_set.txt", mode='r', encoding='utf-8')8for line in f1:9 pairs = line.split(":")10 abbr_word = pairs[0]11 if abbr_word == "n":12 continue13 complete_word = pairs[1].strip()14 complete_word = complete_word.split(" ")15 for i in range(len(complete_word)):16 complete_word[i] = complete_word[i].split("/")[0]17 dump_json[abbr_word] = ''.join(complete_word)18f2 = open("test_set.txt", mode='r', encoding='utf-8')19for line in f2:20 pairs = line.split(":")21 abbr_word = pairs[0]22 if abbr_word == "n":23 continue24 complete_word = pairs[1].strip()25 complete_word = complete_word.split(" ")26 for i in range(len(complete_word)):27 complete_word[i] = complete_word[i].split("/")[0]28 dump_json[abbr_word] = ''.join(complete_word)29f3 = open("train_set.txt", mode='r', encoding='utf-8')30for line in f3:31 pairs = line.split(":")32 abbr_word = pairs[0]33 if abbr_word == "n":34 continue35 complete_word = pairs[1].strip()36 complete_word = complete_word.split(" ")37 for i in range(len(complete_word)):38 complete_word[i] = complete_word[i].split("/")[0]39 dump_json[abbr_word] = ''.join(complete_word)40# dicts = json.load(f)41# # 将多个字典从json文件中读出来42# for i in dicts:43# print(i["uid"])44# print(i["name"])45# print(i["content"])46# print("========")47#48# print(pre_data)49# for i in range(len(pre_data)-1):50# # 如果以xls为为结尾,就是新员工信息51#52# dump_json["uid"] = uid53# dump_json["name"] = name54# dump_json["gender"] = ""55# dump_json["nation"] = ""56# dump_json["birthday"] = ""57# dump_json["birthplace"] = ""58# dump_json["origo"] = ""59#60# dump_json["t_party"] = ""61# dump_json["t_job"] = ""62#63# dump_json["ft_edu_career"] = ""64# dump_json["ft_edu_school"] = ""65# dump_json["pt_edu_career"] = ""66# dump_json["pt_edu_school"] = ""67#68# dump_json["position"] = ""69# dump_json["rank"] = ""70# dump_json["content"] = content71#72# dump_list.append(dump_json)73# content = []74# dump_json = {}75#76#77#78#79# print(dump_list)80#81with open('abbr_pairs.json', mode='w', encoding='utf-8') as f:82 json.dump(dump_json, f, ensure_ascii=False)83#84#85# with open(data_path + '/sample_data180.json', mode='r', encoding='utf-8') as f:86# dicts = json.load(f)87# # 将多个字典从json文件中读出来88# for i in dicts:89# print(i["uid"])90# print(i["name"])91# print(i["content"])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful