diff --git a/webgen.py b/webgen.py index 0b0037f..c4e8761 100755 --- a/webgen.py +++ b/webgen.py @@ -1,31 +1,50 @@ #!/usr/bin/env python3 -import sys, os, re, markdown, datetime +import sys, os, uuid, shutil, subprocess, markdown, re, datetime -# Getoptions -try: - parameters = sys.argv[1] -except: - sys.exit( - sys.argv[0] - + ": Bitte eine Text oder Markdowndatei angeben.\ Dieses Tool wandelt eine entsprechende Datei in Html - ohne Endung, mit Datum. mit --html wird .html als Endung angehängt" - ) +sourcedir = os.path.expanduser("~/") +sourcefile = sourcedir + "up.php" +targetdir = os.path.expanduser("~/www/i21k.de/") +fileending = "" -if parameters == "--html": - fileending = ".html" - try: - parameters = sys.argv[2] - except: - sys.exit( - sys.argv[0] - + ": Bitte eine Text oder Markdowndatei angeben.\ Dieses Tool wandelt eine entsprechende Datei in Html - ohne Endung, mit Datum. mit --html wird .html als Endung angehängt" - ) -else: - fileending = "" +def edit(headline): + editor = os.getenv("EDITOR") + if not editor: + editor = "vim" + subprocess.call([editor, headline]) + return headline -mark_down_file = parameters + +# Parse arguments "--html" and "Some Headline" + +if len(sys.argv) == 1: + headline = input("Bitte gib eine Headline ein: ") +elif len(sys.argv) == 2: + if sys.argv[1] == "--html": + fileending = ".html" + headline = input("Bitte gib eine Headline ein: ") + else: + headline = str(sys.argv[1]) +elif len(sys.argv) == 3: + if sys.argv[1] == "--html": + fileending = ".html" + headline = str(sys.argv[2]) + elif sys.argv[2] == "--html": + fileending = ".html" + headline = str(sys.argv[1]) + else: + sys.exit(str(sys.argv[0]) + ' [--html] "some Headline"\nIf --html is choosen, output will be written to STDOUT.') + + +headlinemd = headline + ".md" +headlinehtml = headline + fileending +print("Headlinefile= ", headlinemd, "\n", "Outputfile= ", headlinehtml) +a = input("Press to continue: ") +edit(headlinemd) + +mark_down_file = headlinemd creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") @@ -33,15 +52,15 @@ creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") if re.match(".*\.md$", mark_down_file): new_file_name = creationtime + " " + re.sub(".md$", fileending, mark_down_file) html_out_file = open(new_file_name, "w") - title_of_text = re.sub(".md$", "", mark_down_file) + title_of_tfileending = re.sub(".md$", "", mark_down_file) else: html_out_file = sys.stdout - title_of_text = mark_down_file + title_of_tfileending = mark_down_file head1 = ( '\n\ -\n' - + title_of_text +<meta http-equiv="content-type" content="tfileending/html; charset=UTF-8">\n<title>' + + title_of_tfileending + '\n\ \n\