From 1b4289bc8e81a1e557135692c987e39ae806eb3a Mon Sep 17 00:00:00 2001 From: qq_44193969 Date: Fri, 12 Nov 2021 15:20:30 +0800 Subject: [PATCH] add template for lanqiao --- leetcode_helper.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/leetcode_helper.py b/leetcode_helper.py index 7ccc8e8db..8b54b35f1 100644 --- a/leetcode_helper.py +++ b/leetcode_helper.py @@ -467,6 +467,33 @@ def add_color_for_special_exercises(): +def add_solution_md_template_for_lanqiao(): + data_dir = 'data_backup/3.蓝桥杯' + dirs_ = os.listdir(data_dir) + dirs = [] + for dir in dirs_: + dir = os.path.join(data_dir, dir) + if os.path.isdir(dir): + dirs.append(dir) + for dir in dirs: + assert os.path.isdir(dir) + + solution_md_path = os.path.join(dir, 'solution.md') + if not os.path.exists(solution_md_path): + template_path = 'lanqiao_template.md' + title = dir.split('/')[-1].split('.')[-1] + desc_path = os.path.join(dir, 'desc.md') + with open(desc_path, 'r', encoding='utf-8') as f: + desc_data = f.read() + with open(template_path, 'r', encoding='utf-8') as f: + template_data = f.read() + template_data = template_data.replace('# 两数之和\n', '# {}\n\n{}'.format(title, desc_data)) + print(template_data) + with open(solution_md_path, 'w', encoding='utf-8') as f: + f.write(template_data) + + + @@ -479,7 +506,7 @@ if helper_function == 'modify_back_up_dir_name': -add_color_for_special_exercises() +add_solution_md_template_for_lanqiao() -- GitLab