From b12cd4ddb29022f38a2c2125996c7c357484a972 Mon Sep 17 00:00:00 2001 From: hamdy Date: Thu, 19 Nov 2020 11:44:14 +0200 Subject: [PATCH] add filter --- filter.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 filter.py diff --git a/filter.py b/filter.py new file mode 100644 index 000000000..1798838e6 --- /dev/null +++ b/filter.py @@ -0,0 +1,50 @@ +import toml +import os +import shutil + +def getListOfFiles(dirName): + # create a list of file and sub directories + # names in the given directory + listOfFile = os.listdir(dirName) + allFiles = list() + # Iterate over all the entries + for entry in listOfFile: + # Create full path + fullPath = os.path.join(dirName, entry) + # If entry is a directory then get the list of files in this directory + if os.path.isdir(fullPath): + allFiles = allFiles + getListOfFiles(fullPath) + else: + allFiles.append(fullPath) + + return allFiles +def do(): + files = getListOfFiles("content") + for file in files: + if not file.endswith(".md"): + continue + + t = "" + start = False + + with open(file) as f: + for line in f: + if line.startswith("---"): + if not start: + start = True + continue + else: + break + + if line.startswith("private:"): + if line.replace("private:", "").strip() == "1": + shutil.rmtree(os.path.abspath(os.path.dirname(file))) + else: + continue + + + + + +if __name__ == "__main__": + do() \ No newline at end of file