2.0: webgen.py +commandlineopts +edit
This commit is contained in:
parent
e4bdcb5991
commit
19466e82f4
1 changed files with 45 additions and 27 deletions
72
webgen.py
72
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 <RETURN> 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 = (
|
||||
'<!DOCTYPE HTML><html><head>\n\
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n<title>'
|
||||
+ title_of_text
|
||||
<meta http-equiv="content-type" content="tfileending/html; charset=UTF-8">\n<title>'
|
||||
+ title_of_tfileending
|
||||
+ '</title>\n\
|
||||
<meta name="syntax" content="markdown">\n\
|
||||
<meta name="generator" content="'
|
||||
|
@ -68,8 +87,7 @@ pre { white-space: pre-wrap; font-family: monospace; color: #00f020; font-backgr
|
|||
.Statement { color: #00f020; font-weight: bold; }\n\
|
||||
.Headandfoot { color: #00f020; font-weight: bold; } "
|
||||
|
||||
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
|
||||
|
||||
style_fn = '<link rel="stylesheet" type="tfileending/css" href="/vimstyles.css">'
|
||||
head2 = "</head><body>\n"
|
||||
body1 = '<a href="./">Back</a>'
|
||||
foot = "</body> </html>"
|
||||
|
|
Loading…
Reference in a new issue