| import os |
| import re |
| import shutil |
| |
| import easygui |
| from easygui import * |
| |
| |
| class User(EgStore): |
| def __init__(self, filename): |
| self.path = '' |
| EgStore.__init__(self, filename) |
| |
| |
| def get_dir_path_gui(): |
| |
| user = User("settings.txt") |
| |
| user.restore() |
| file_path = easygui.diropenbox(default=user.path) |
| user.path = file_path |
| user.store() |
| return file_path |
| |
| |
| def get_root_dir(dir_path): |
| file_list = os.listdir(dir_path) |
| path_list = [] |
| for file in file_list: |
| |
| if file.startswith('.'): |
| continue |
| |
| is_file = re.findall(r'\.[^.\\/:*?"<>|\r\n]+$', file) |
| if len(is_file): |
| continue |
| |
| res_abort = re.findall(re.compile(r'(__pycache__|venv|build|dist|node_modules|public|LICENSE)'), file) |
| if len(res_abort): |
| continue |
| |
| file_path = os.path.join(dir_path, file) |
| path_list.append(file_path) |
| return path_list |
| |
| |
| def setDir(filepath): |
| ''' |
| 如果文件夹不存在就创建,如果文件存在就清空! |
| :param filepath:需要创建的文件夹路径 |
| :return: |
| ''' |
| if not os.path.exists(filepath): |
| os.mkdir(filepath) |
| else: |
| shutil.rmtree(filepath, ignore_errors=True) |
| os.mkdir(filepath) |
| |
| |
| def cnblog2anki(file): |
| path_list = [] |
| with open(file, "r", encoding='utf-16') as f: |
| bookmarks = f.readlines() |
| for index, bookmark in enumerate(bookmarks): |
| |
| if index == 0 or bookmark == '\n': |
| continue |
| path = bookmark.split('=', 1)[1].strip() |
| path_list = path.split('\\') |
| new_path = ".\\AA提取\\" + path_list.pop() |
| if index == 1: |
| mkdir(".\\AA提取") |
| shutil.copy(path, new_path) |
| |
| |
| def mkdir(path): |
| |
| path = path.strip() |
| |
| path = path.rstrip("\\") |
| |
| |
| |
| |
| isExists = os.path.exists(path) |
| |
| |
| if not isExists: |
| |
| |
| os.makedirs(path) |
| return True |
| else: |
| |
| print('已存在') |
| |
| |
| |
| |
| def get_deep_dirs(path): |
| file_path = [] |
| for root, dirs, files in os.walk(path): |
| |
| for file in files: |
| |
| res_abort = re.findall(re.compile(r'(\.json|d\.ts)$'), file) |
| if res_abort: |
| continue |
| |
| res_abort2 = re.findall(re.compile(r'(assets)'), file) |
| if len(res_abort2): |
| continue |
| |
| res_save = re.findall(re.compile(r'(\.py|vue|js|ts)$'), file) |
| if len(res_save): |
| file_path.append(os.path.join(root, file)) |
| return file_path |
| |
| |
| def read_file(file_path, root_path): |
| suffix = re.findall(r'\.[^.\\/:*?"<>|\r\n]+$', file_path) |
| if len(suffix): |
| suffix = suffix[0][1:] |
| with open(file_path, "r", encoding='utf-8') as f: |
| head_line = f.readline() |
| rest_line = f.read() |
| write2md(head_line, head_line + rest_line, suffix,file_path, root_path) |
| |
| def write2md(head, content, suffix,file_path, root_path): |
| with open(root_path + '/NOTE.md', "a", encoding='utf-8') as f: |
| f.write(f"# {head}\n\n") |
| f.write(f"## {file_path}\n") |
| f.write(f"```{suffix}\n") |
| f.write(content) |
| f.write(f"```\n") |
| |
| if __name__ == '__main__': |
| root_path = get_dir_path_gui() |
| res = get_root_dir(root_path) |
| for dir_path in res: |
| file_path = get_deep_dirs(dir_path) |
| for file in file_path: |
| read_file(file,root_path) |
| ``` |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战