diff --git a/leetcode_helper.py b/leetcode_helper.py index 603605bc972fab176ced775e7d6512caa950cff4..2e851dc6e6e0f4dac8739fb45e39ae4148bd1196 100644 --- a/leetcode_helper.py +++ b/leetcode_helper.py @@ -378,7 +378,7 @@ def leetcode_helper_add_sloutionjson(): def fix_bug(): - data_dir = 'data_backup/3.蓝桥杯' + data_dir = 'data_backup/1.leetcode' dirs_ = os.listdir(data_dir) dirs = [] for dir in dirs_: @@ -388,15 +388,43 @@ def fix_bug(): for dir in dirs: assert os.path.isdir(dir) - config_json_path = os.path.join(dir, 'config.json') - print(config_json_path) + solution_md_path = os.path.join(dir, 'solution.md') + if not os.path.exists(solution_md_path): + continue + with open(solution_md_path, 'r', encoding='utf-8') as f: + solution_md_data = f.read() + print(dir) + title = dir.split('/')[-1].split('-')[-1] + print(title) + solution_md_data = solution_md_data.replace('# 两数之和', '# {}'.format(title)) + if solution_md_data.find('# {}\n\n'.format(title)) == -1: + solution_md_data = solution_md_data.replace('# {}'.format(title), '# {}\n'.format(title)) + if solution_md_data.find('## aop\n\n') == -1: + solution_md_data = solution_md_data.replace('## aop', '## aop\n') + + if solution_md_data.find('## 答案\n\n') == -1: + solution_md_data = solution_md_data.replace('## 答案', '## 答案\n') + + if solution_md_data.find('## 选项\n\n') == -1: + solution_md_data = solution_md_data.replace('## 选项', '## 选项\n') + + if solution_md_data.find('### before\n\n') == -1: + solution_md_data = solution_md_data.replace('### before', '### before\n') + + if solution_md_data.find('### after\n\n') == -1: + solution_md_data = solution_md_data.replace('### after', '### after\n') + + if solution_md_data.find('\n\n```cpp') == -1: + solution_md_data = solution_md_data.replace('```cpp', '\n```cpp') + + if solution_md_data.find('\n\n### ') == -1: + solution_md_data = solution_md_data.replace('### ', '\n### ') + with open(solution_md_path, 'w', encoding='utf-8') as f: + f.write(solution_md_data) + + + - with open(config_json_path, 'r', encoding='utf-8') as f: - config_data = json.load(f) - del config_data['title'] - config_data_json = json.dumps(config_data, ensure_ascii=False, indent=2) - with open(config_json_path, 'w', encoding='utf-8') as f: - f.write(config_data_json)