zoukankan      html  css  js  c++  java
  • 利用python生成gitbook目录文件

    将 summary-generator.py 放在已知根目录下。

    开发环境:

    • macOS
    • python 3

    完整代码:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import os, sys
    
    path = "."
    result_list = []
    result_str = ""
    flag = "* "
    tab = "  "
    # 定义递归方法
    def find_files(path, n = 0, dir = ""):
        global result_str
        if os.path.isdir(path):
            if path <> "node_modules" and path <> "_book" and path <> ".DS_Store":
                if path <> ".":
                    dir += path + "/"
                # path是文件夹
                if path <> ".":
                    result_list.append(tab * n + flag + "[" + path + "](" + dir + "/README.md" + ")")
                    result_str += tab * n + flag + "[" + path + "](" + dir + "/README.md"  + ")
    "
                    n = n + 1
                else:
                    n = 0
                # 按文件名称排序
                dirs = sorted(os.listdir(path))
                for file in dirs:
                    find_files(file, n, dir)
        else:
            # path是文件
            if path.endswith(".md") and path <> "SUMMARY.md" and path <> "README.md":
                result_list.append(tab * n + flag + "[" + path + "](" + dir + path + ")")
                result_str += tab * n + flag + "[" + path + "](" + dir + path + ")
    "
    find_files(".", 0, "")
    for file in result_list:
        print file
    try:
        f = open('./SUMMARY.md', 'w')
        f.write(result_str)
    finally:
        if f:
            f.close()
    
  • 相关阅读:
    4-6 随机数
    linux下安装jdk
    markdown使用教程
    IDE新建gradle各种坑
    day05泛型类和泛型方法
    day05集合
    day15 Ui自动化中三种等待方式
    day15 Ui自动化元素的定位
    Windows系统
    解决sublime text 3使用Install Package时出现There are no packages available for installation问题
  • 原文地址:https://www.cnblogs.com/longying2008/p/15068115.html
Copyright © 2011-2022 走看看