async def view_code(request: Request, name: str = '001_Two_Sum'): global code_name_map if name not in code_name_map: return templates.TemplateResponse("index.html", { "request": request, "message": 'Easy Leetcode' }) # 代码路径 code_path = code_name_map[name][1] # 代码markdwon路径 code_md_path = code_name_map[name][2] code_str = code_util.get_file_read(code_path) code_md_str = code_util.get_file_read(code_md_path) code_res = '\n'.join(code_util.call_py_file(code_path, python_path)) data = { 'code_str': code_str, 'code_md_str': code_md_str, 'name': name, 'code_res': code_res } # every times view code,path config.count_view_code 's count +=1 (view code count log) utils.add_file_txt_count(config.count_view_code) return templates.TemplateResponse("code_view.html", { "request": request, "data": data, "message": name })
async def view_md(request: Request, name: str = '001_Two_Sum'): global code_name_map if name not in code_name_map: return templates.TemplateResponse("index.html", { "request": request, "message": 'Easy Leetcode' }) # 代码markdwon路径 code_md_path = code_name_map[name][2] code_md_str = code_util.get_file_read(code_md_path) data = { 'code_md_str': code_md_str, 'name': name, } return templates.TemplateResponse("md.html", { "request": request, "data": data, "message": name })
async def view(request: Request): count_day = utils.get_file_txt_count(config.count_day) count_view_code = utils.get_file_txt_count(config.count_view_code) data = { 'all_num': len(code_name_list), 'count_day': count_day, 'count_view_code': count_view_code, 'code_name_list': code_name_list } return templates.TemplateResponse("code_list.html", { "request": request, "data": data, "message": "Leetcode List" })
async def view(request: Request, keyword: str = 'L'): count_day = utils.get_file_txt_count(config.count_day) count_view_code = utils.get_file_txt_count(config.count_view_code) f_code_name_list = [ni for ni in code_name_list if keyword in ni[1]] data = { 'all_num': len(code_name_list), 'count_day': count_day, 'count_view_code': count_view_code, 'code_name_list': f_code_name_list } return templates.TemplateResponse("code_list.html", { "request": request, "data": data, "message": "Leetcode List" })
async def about(request: Request): return templates.TemplateResponse("about.html", { "request": request, "message": 'Easy Leetcode' })
async def index(request: Request): return templates.TemplateResponse("index.html", { "request": request, "message": 'Easy Leetcode' })