From b6ce0eaf4748c75e7e209302ef7a78aaf390d6c0 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 2 May 2022 22:57:37 +0200 Subject: [PATCH] adds an automated TOC script --- generate_toc.py | 34 ++++++++++++++++++++++++++++++++++ readme.md | 26 ++++++++++++++++++++------ 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 generate_toc.py diff --git a/generate_toc.py b/generate_toc.py new file mode 100644 index 0000000..ac45482 --- /dev/null +++ b/generate_toc.py @@ -0,0 +1,34 @@ +import subprocess + + +LINK = "https://github.com/ekalinin/github-markdown-toc" +OUTPUT = "readme.md" +INPUT = [ + "learning_python3.md", + "learning_python3_gui.md", + "learning_git.md", + ] +CMD = "gh-md-toc" +FILTER = "(#" + + +if __name__ == "__main__": + try: + p = subprocess.Popen([CMD], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, err = p.communicate() + except Exception as e: + print("please install {}".format(LINK)) + exit() + CONTENT = [] + for f in INPUT: + p = subprocess.Popen([CMD, f], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, err = p.communicate() + output = output.decode().split("\n") + for line in output: + if FILTER in line: + line = line.replace(FILTER, "(./{}#".format(f)) + CONTENT.append(line) + with open(OUTPUT, "w") as fp: + for line in CONTENT: + fp.write("{}\n".format(line)) + print("done...") diff --git a/readme.md b/readme.md index 52c1a99..20cb434 100644 --- a/readme.md +++ b/readme.md @@ -103,6 +103,8 @@ Table of Contents * [Introduction to the requests library](./learning_python3.md#introduction-to-the-requests-library) * [Threading](./learning_python3.md#threading) +Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) + Table of Contents ================= @@ -121,13 +123,25 @@ Table of Contents * [Coding challenge - Login generator with GUI](./learning_python3_gui.md#coding-challenge---login-generator-with-gui-1) * [Coding challenge - Trivial pursuit with GUI](./learning_python3_gui.md#coding-challenge---trivial-pursuit-with-gui-1) +Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) + + Table of Contents ================= -* [Git](./learning_git.md#git) - * [Git in Pycharm](./learning_git.md#git-in-pycharm) - * [Starting a version controlled project](./learning_git.md#starting-a-version-controlled-project) - * [Creating an online repository](./learning_git.md#creating-an-online-repository) - * [Cloning the remote project into a new project](./learning_git.md#cloning-the-remote-project-into-a-new-project) - * [Updating the original project](./learning_git.md#updating-the-original-project) +* [About](./learning_git.md#about) +* [Git via bash](./learning_git.md#git-via-bash) + * [Initialing a git repo](./learning_git.md#initialing-a-git-repo) + * [What's in this repo](./learning_git.md#whats-in-this-repo) + * [Adding and tracking content](./learning_git.md#adding-and-tracking-content) + * [The main workflow](./learning_git.md#the-main-workflow) +* [Git via Atom](./learning_git.md#git-via-atom) +* [Git via Pycharm](./learning_git.md#git-via-pycharm) + * [Starting a version controlled project](./learning_git.md#starting-a-version-controlled-project) + * [Creating an online repository](./learning_git.md#creating-an-online-repository) + * [Adding some changes to our local code](./learning_git.md#adding-some-changes-to-our-local-code) + * [Cloning the remote project into a new project](./learning_git.md#cloning-the-remote-project-into-a-new-project) + * [Updating the original project](./learning_git.md#updating-the-original-project) + +Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)