From f84152af820289629eb32e23c54b6c7bbde06561 Mon Sep 17 00:00:00 2001 From: Ashik K Date: Sat, 8 Apr 2023 09:25:28 +0200 Subject: [PATCH] wip: add python script to generate static site --- genstatic.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 genstatic.py diff --git a/genstatic.py b/genstatic.py new file mode 100644 index 0000000..df53c23 --- /dev/null +++ b/genstatic.py @@ -0,0 +1,28 @@ +# create a file named index.html +# and insert links to every html file in the +# directory that was passed as a command line argument +import sys +import os +from pathlib import Path + +# check if the user supplied the correct number of command line arguments +if len(sys.argv) != 2: + print("Usage: python index.py htmlfilesdirectory") + sys.exit(1) + +# set the directory from the command line argument +dir = sys.argv[1] +# create a file named index.html +outfile = open("index.html", "w") +#write a tag to the file +outfile.write("") +# insert links to every html file in the +# directory that was passed as a command line argument +for file in os.listdir(dir): + if file.endswith(".html"): + # write the link to the html file + outfile.write("" + file + "
") +# close the file +#write a tag to the file +outfile.write("") +outfile.close \ No newline at end of file