当前位置: 首页 > news >正文

网站建设swot/百度免费发布信息网站

网站建设swot,百度免费发布信息网站,网上购物平台有哪些?,网站如何做好内链把项目转换为md知识库,提供给gpts使用 import osimport chardetproject_path # 项目目录路径 project_name # 项目名称# 定义全局字典,映射文件后缀名到Markdown代码块的语言 language_mapping {.java: java,.py: python,.js: javascript,.html: html,…

把项目转换为md知识库,提供给gpts使用

import osimport chardetproject_path='' # 项目目录路径
project_name='' # 项目名称# 定义全局字典,映射文件后缀名到Markdown代码块的语言
language_mapping = {'.java': 'java','.py': 'python','.js': 'javascript','.html': 'html','.md': 'markdown','.properties': 'properties','.xml': 'xml','.vue': 'vue','.tsx': 'tsx','.yml': 'yaml','.sql': 'sql','.json': 'json','.txt': 'text','.csv': 'csv','.ini': 'ini','.c': 'c','.cpp': 'cpp','.go': 'go','.php': 'php','.rb': 'ruby',
}def detect_encoding(file_path):"""检测文件编码"""with open(file_path, 'rb') as file:raw_data = file.read()result = chardet.detect(raw_data)return result['encoding']def write_file_content_to_utf8(file_path, output_file):"""读取文件并以UTF-8编码写入到txt文件中"""# 获取文件后缀名_, ext = os.path.splitext(file_path)# 检查文件大小(20KB = 20480 字节)# if os.path.getsize(file_path) > 91136 and ext != '.md':if os.path.getsize(file_path) > 91136:print(f"忽略大文件:{file_path}")returnencoding = detect_encoding(file_path)try:with open(file_path, 'r', encoding=encoding) as file:content = file.read()relative_path = os.path.relpath(file_path, project_path)  # 计算相对路径output_file.write(f"## 文件:{project_name}\\{relative_path}\n\n")  # Markdown标题if not ext == '.md':# 根据文件后缀名确定代码块的语言language = language_mapping.get(ext, 'text')  # 默认为'text'output_file.write(f"```{language}\n")  # 语法高亮output_file.write(content)if not ext == '.md':output_file.write("\n```\n\n")  # 结束代码块else:output_file.write("\n\n")  # 结束代码块except UnicodeDecodeError:print(f"读取失败(编码不支持):{file_path}")def should_ignore(directory,ignored_directories):"""检查是否应该忽略给定的目录"""for ignored_dir in ignored_directories:if ignored_dir in directory:return Truereturn Falsedef process_directory(directory, output_file,ignored_directories):"""递归处理目录下的所有文件和子目录"""if should_ignore(directory,ignored_directories):return  # 忽略整个目录for item in os.listdir(directory):path = os.path.join(directory, item)if os.path.isdir(path):process_directory(path, output_file,ignored_directories)elif any(path.endswith(suffix) for suffix in file_suffixes):print('path===============',path)write_file_content_to_utf8(path, output_file)def create_knowledge_base(project_directory, output_path):"""创建知识库文件"""with open(output_path, 'w', encoding='utf-8') as output_file:process_directory(project_directory, output_file,ignored_directories)def create_knowledge_base(paths, output_path):"""创建知识库文件"""global project_path,project_namewith open(output_path, 'w', encoding='utf-8', errors='ignore') as output_file:for project_directory in paths:project_path=project_directoryproject_name = os.path.basename(project_path)  # 提取项目名称output_file.write(f"# 项目:{project_name}\n\n")  # Markdown标题process_directory(project_directory, output_file,ignored_directories)if __name__ == '__main__':ignored_directories = ['target','.idea','node_modules','build','dist','out','logs','log','lib','js_sdk','uni_modules','nativeplugins','static','public']file_suffixes=['.java', '.properties', '.yml', '.md', '.txt','.js','.html','.vue','.xml','.json','.sql','.csv','.py','.tsx','.ts','.less','.scss','.gradle']project_dirs = ['H:\\下载\edge浏览器下载\\spring-security-6.1.6',]output_path = 'spring-security-6.1.6.md' # 知识库文件的输出路径create_knowledge_base(project_dirs, output_path)

detect_encoding(file_path): 检测并返回文件的编码类型。
write_file_content_to_utf8(file_path, output_file): 读取文件内容,根据文件扩展名决定是否加上 Markdown 代码块的格式,并写入到指定的输出文件中。
should_ignore(directory, ignored_directories): 判断给定的目录是否应该被忽略。
process_directory(directory, output_file, ignored_directories): 递归处理给定目录下的所有文件和子目录,转换为 Markdown 格式。
create_knowledge_base(paths, output_path): 遍历给定的项目目录列表,为每个项目创建 Markdown 格式的知识库文件。

http://www.whsansanxincailiao.cn/news/31992924.html

相关文章:

  • 淘宝网站制作/百度搜索引擎首页
  • 手机电商网站开发/口碑营销案例2022
  • 图书馆网站建设费用/收录好的网站
  • 职业生涯规划大赛作品/福州百度快速优化
  • 昆山高端网站建设/视频号视频下载助手app
  • 石家庄做网站电话/产品网络营销推广方案
  • 昆明做网站的旅行社/seo搜索引擎优化是什么意思
  • 安徽龙山建设有限公司网站/今日油价92汽油价格
  • 红旗渠建设集团网站/杭州百度
  • 网站建设找哪家好/路由优化大师
  • wordpress怎么做淘客网站/市场营销推广活动方案
  • 住房建设厅网站/全网营销推广怎么做
  • 免费的带货视频素材网站/百度指数与百度搜索量
  • 公司做小程序要多少钱/快手seo关键词优化
  • 网站群建设情况/宁德市中医院
  • office做的网站/免费域名注册二级域名
  • wordpress测试数据/杭州网站优化方案
  • 做视频网站要多大的主机/爱站网seo综合查询工具
  • 品牌型网站/百度收录查询工具官网
  • qq网站代码/开发软件app需要多少钱
  • 网站群建设方案/石家庄seo顾问
  • 佛山网站建设联系电话/宁波网站推广
  • 深圳注册公司需要哪些材料和流程/宜昌seo
  • 程序员做个网站要多少钱呢/友情链接平台哪个好
  • 昆明如何做百度的网站/seo外包服务方案
  • 宁乡电商网站建设报价/林哥seo
  • 凡客vancl的网站标题/最新百度快速排名技术
  • 外贸营销型网站建设多少钱/百度账号查询
  • 网站建设怎么做/天堂网长尾关键词挖掘网站
  • 广州十度网络网站开发最好/深圳sem优化