From 4bd7ec45dea714689e5ab40c24589262bf042ced Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Thu, 31 Aug 2023 19:48:38 +0200 Subject: [PATCH] webgen v4.0.6 for batch usage --- webgen-ni.py | 67 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/webgen-ni.py b/webgen-ni.py index eb3149f..1fc76e2 100755 --- a/webgen-ni.py +++ b/webgen-ni.py @@ -1,20 +1,38 @@ #!/usr/bin/env python3 -import sys, os, uuid, shutil, signal, subprocess, markdown, re, datetime, locale, glob +import sys, os, uuid, shutil, signal, subprocess, markdown2 as markdown, re, datetime, locale, glob from dialog import Dialog # If not choosen stdout as output, where should the generated file go to and what -# fileending (f.e. .html) shall it have +# fileending (f.e. .html) shall it have. Preset values. webbasedir = os.path.expanduser("~/www/i21k.de/") targetdir = webbasedir + "posts/" -sourcedir = os.path.expanduser("~/python/webgen/") +sourcedir = os.path.expanduser("~/python/webgen/mds/") + ### for module mkdirindex: filesdir = webbasedir + "files/" indexfilename = "index.html" filesdirheadline = "Files" #### +# for spellchecko +# Preferred: aspell -c filename +# +dospellcheck = os.getenv("SPELLCHECK") +spellcheck = "aspell" +spellcheckparam = "-c" + +# Configure Markdown, activate "break-on-newline" for letting a line end without havin to put doublespaces there. +# +# More options: +# break-on-newline, code-friendly, cuddled-lists, fenced-code-blocks, +# footnotes, header-ids, highlightjs-lang, html-classes, link-patterns, +# markdown-in-html, numbering, pyshell, smarty-pants, spoiler, strike, +# tag-friendly, tables, toc, use-file-vars, wiki-tables, xml + +markdown.Markdown.extras = ["footnotes", "break-on-newline"] + fileending = "" locale.setlocale(locale.LC_ALL, "") clear = "\x1b[2J\x1b[H" @@ -47,11 +65,19 @@ signal.signal(signal.SIGINT, sigint_handler) # call favorite editor with filename to write the text +# i am not shure bout that spellchecko, is it nessesary? + + def edit(headline): editor = os.getenv("EDITOR") if not editor: editor = "vim" subprocess.call([editor, headline]) + if dospellcheck: + print(yellow) + if input("You like to spellcheck it first [y/N]?") == "y": + subprocess.call([spellcheck, spellcheckparam, headline]) + print(green) return headline @@ -80,7 +106,7 @@ def selectfile(): # Nothing has been choosen, so lets ask for a topic to generate a filename 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] == "": sys.exit(yellow + "Na, dann eben nicht...") headline = newtopic[1] @@ -92,7 +118,7 @@ def selectfile(): headline = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1]) print(headline) -# a = input(yellow + "What do we dooo here?") + # a = input(yellow + "What do we dooo here?") # if the searched filename doesnt match an existing file we construct a new one if len(glob.glob(sourcedir + headline + ".md")) == 0: @@ -110,6 +136,7 @@ def selectfile(): return sourcefile, targetfile, headline + def mkdirindex(filesdir, indexfilename, filesdirheadline): """Dig the files-directory and generate an index.""" @@ -122,12 +149,12 @@ def mkdirindex(filesdir, indexfilename, filesdirheadline): ) style_fn = '' - head2 = "" + head2 = "
\n" body1 = 'Back


' body1 += '
Some files. Maybe useful or not.
' body1 += '' - foot = "

You can't avoid chaos.

\n" - linecounter=0 + foot = '
You can\'t avoid chaos.

\n' + linecounter = 0 dirindexfile = open(filesdir + indexfilename, "w") @@ -147,20 +174,19 @@ def mkdirindex(filesdir, indexfilename, filesdirheadline): line = str('' + str(file) + " " + sizestr + "") dirindexfile.write(line) - linecounter+=1 + linecounter += 1 dirindexfile.write(foot) return linecounter - -# Parse arguments "--html", "--stdout" and "Some Headline" +# Parse arguments "--html", "--stdout", --spellcheck and "Some Headline" # there are 3 parameters. if --html is given, the fileending will be .html. # Else, if stdout is choosen there can be no fileending, but it will still contain html # the name of the program is stored in myname # dont set a name to outfile, it just is initialised here and will be overwritten -optwords = ["--html", "--stdout"] +optwords = ["--html", "--stdout", "--spellcheck"] outfile = "" args = sys.argv myname = args.pop(0) @@ -169,6 +195,9 @@ for wish in optwords: if wish == "--html": fileending = ".html" args.pop(args.index(wish)) + if wish == "--spellcheck": + dospellcheck = "y" + args.pop(args.index(wish)) if wish == "--stdout": outfile = sys.stdout args.pop(args.index(wish)) @@ -199,8 +228,8 @@ elif len(args) > 1: if outfile == sys.stdout: outputfile = "STDOUT" print(yellow + "\nYou will edit now: '" + green + inputfile + yellow + "'\nOutputfile= '" + green + outputfile + "'") -#a = input("\nPress to continue or to stop: ") -#edit(inputfile) +# a = input("\nPress to continue or to stop: ") +# edit(inputfile) # Set ouput to stdout, if requested. Caution, the prompts of this script go there, too, @@ -228,11 +257,11 @@ head1 = ( # Some fancy css for minimalistic terminal style + style_fn = '' -head2 = "\n" +head2 = "\n
\n" body1 = 'Back
Moin

' -foot = "


\n" -foot = "

\n" +foot = '

\n \n' # write beginning of html-file html_out_file.write(head1 + style_fn + head2 + body1) @@ -250,7 +279,7 @@ if outfile != sys.stdout: print(outputfile) # Dig the files-directory and generate an index. -linecounter=mkdirindex(filesdir, indexfilename, filesdirheadline) -print("Dirindex in ",filesdir," has ", linecounter, "lines") +linecounter = mkdirindex(filesdir, indexfilename, filesdirheadline) +print("Dirindex in ", filesdir, " has ", linecounter, "lines") # Have a nice time.