webgen v4.0.2 + error in html-naming corrected
This commit is contained in:
parent
aa4f89aa85
commit
86827319db
1 changed files with 28 additions and 7 deletions
35
webgen.py
35
webgen.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys, os, uuid, shutil, subprocess, markdown, re, datetime, locale, glob
|
import sys, os, uuid, shutil, signal, subprocess, markdown, re, datetime, locale, glob
|
||||||
from dialog import Dialog
|
from dialog import Dialog
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,12 @@ sourcedir = os.path.expanduser("~/python/webgen/")
|
||||||
fileending = ""
|
fileending = ""
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
locale.setlocale(locale.LC_ALL, "")
|
||||||
clear = "\x1b[2J\x1b[H"
|
clear = "\x1b[2J\x1b[H"
|
||||||
|
green = "\x1b[38;5;46m"
|
||||||
|
red = "\x1b[38;5;9m"
|
||||||
|
yellow = "\x1b[38;5;226m"
|
||||||
|
greenonblack = "\x1b[38;5;46m\x1b[48;5;16m"
|
||||||
|
redonblack = "\x1b[38;5;9m\x1b[48;5;16m"
|
||||||
|
|
||||||
xwidth = os.get_terminal_size()[0] - 3
|
xwidth = os.get_terminal_size()[0] - 3
|
||||||
ywidth = os.get_terminal_size()[1] - 3
|
ywidth = os.get_terminal_size()[1] - 3
|
||||||
os.chdir(sourcedir)
|
os.chdir(sourcedir)
|
||||||
|
@ -24,6 +30,16 @@ creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||||
# Initialize a dialog.Dialog instance
|
# Initialize a dialog.Dialog instance
|
||||||
d = Dialog(dialog="dialog")
|
d = Dialog(dialog="dialog")
|
||||||
|
|
||||||
|
# Let's stop everything at CTRL-c
|
||||||
|
|
||||||
|
|
||||||
|
def sigint_handler(signum, frame):
|
||||||
|
sys.exit(yellow + "\nPfff....I'll tell your mom!\n")
|
||||||
|
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
|
||||||
|
|
||||||
# call favorite editor with filename to write the text
|
# call favorite editor with filename to write the text
|
||||||
def edit(headline):
|
def edit(headline):
|
||||||
editor = os.getenv("EDITOR")
|
editor = os.getenv("EDITOR")
|
||||||
|
@ -57,14 +73,17 @@ def selectfile():
|
||||||
if ausgewaehlt[0] == "cancel":
|
if ausgewaehlt[0] == "cancel":
|
||||||
newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit")
|
newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit")
|
||||||
if newtopic[0] == "cancel" or newtopic[1] == "":
|
if newtopic[0] == "cancel" or newtopic[1] == "":
|
||||||
sys.exit("Na, dann eben nicht...")
|
sys.exit(yellow + "Na, dann eben nicht...")
|
||||||
headline = newtopic[1]
|
headline = newtopic[1]
|
||||||
else:
|
else:
|
||||||
headline = ""
|
headline = ""
|
||||||
|
|
||||||
# Clean filename from leading .md for later construction of a headline
|
# Clean filename from leading .md for later construction of a headline
|
||||||
if headline == "":
|
if headline == "":
|
||||||
|
|
||||||
headline = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1])
|
headline = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1])
|
||||||
|
print(headline)
|
||||||
|
a = input(yellow + "What do we dooo here?")
|
||||||
|
|
||||||
# if the searched filename doesnt match an existing file we construct a new one
|
# if the searched filename doesnt match an existing file we construct a new one
|
||||||
if len(glob.glob(sourcedir + headline + ".md")) == 0:
|
if len(glob.glob(sourcedir + headline + ".md")) == 0:
|
||||||
|
@ -105,27 +124,29 @@ for wish in optwords:
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
headline = args[0]
|
headline = args[0]
|
||||||
inputfile = headline + ".md"
|
inputfile = headline + ".md"
|
||||||
outputfile = glob.glob(targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*")
|
outputfile = glob.glob(
|
||||||
|
targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*" + fileending
|
||||||
|
)
|
||||||
outputfilelength = len(outputfile)
|
outputfilelength = len(outputfile)
|
||||||
if outputfilelength >= 1:
|
if outputfilelength >= 1:
|
||||||
outputfile = outputfile[outputfilelength - 1]
|
outputfile = outputfile[outputfilelength - 1]
|
||||||
else:
|
else:
|
||||||
outputfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline
|
outputfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline + fileending
|
||||||
|
|
||||||
|
|
||||||
elif len(args) == 0:
|
elif len(args) == 0:
|
||||||
selection = selectfile()
|
selection = selectfile()
|
||||||
inputfile = selection[0]
|
inputfile = selection[0]
|
||||||
outputfile = selection[1]
|
outputfile = selection[1] + fileending
|
||||||
headline = selection[2]
|
headline = selection[2]
|
||||||
elif len(args) > 1:
|
elif len(args) > 1:
|
||||||
sys.exit("Too much or wrong parameters:\n" + myname + ' [--html] [--stdout] ["Some Topic"] ')
|
sys.exit(red + "Too much or wrong parameters:\n" + yellow + myname + ' [--html] [--stdout] ["Some Topic"] ')
|
||||||
|
|
||||||
|
|
||||||
# This is informal asking yes/no for editing the text
|
# This is informal asking yes/no for editing the text
|
||||||
if outfile == sys.stdout:
|
if outfile == sys.stdout:
|
||||||
outputfile = "STDOUT"
|
outputfile = "STDOUT"
|
||||||
print("\nYou will edit now: '" + inputfile + "'\nOutputfile= '" + outputfile + "'")
|
print(yellow + "\nYou will edit now: '" + green + inputfile + yellow + "'\nOutputfile= '" + green + outputfile + "'")
|
||||||
a = input("\nPress <RETURN> to continue or <CTRL-C> to stop: ")
|
a = input("\nPress <RETURN> to continue or <CTRL-C> to stop: ")
|
||||||
edit(inputfile)
|
edit(inputfile)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue