From fe2203630d00f40916fb6e77fb3aae9378bfe68a Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Mon, 15 Nov 2021 12:43:30 +0100 Subject: [PATCH] module for webgen - select file by menue --- dialogtest2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 dialogtest2.py diff --git a/dialogtest2.py b/dialogtest2.py new file mode 100755 index 0000000..8190247 --- /dev/null +++ b/dialogtest2.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 +import sys, re, os, pg, locale, glob +from dialog import Dialog + +## Initialize a dialog.Dialog instance +d = Dialog(dialog="dialog") + +locale.setlocale(locale.LC_ALL, "") +sourcedir = "/home/wn/python/webgen/" +targetdir = "/home/wn/www/i21k.de/posts/" +sourcefolder = os.listdir(sourcedir) +targetfolder = os.listdir(targetdir) +xwidth = os.get_terminal_size()[0] - 10 +ywidth = os.get_terminal_size()[1] - 10 + +# Put files in sourcefolder into list +zahl = 0 +tabelle = [("", "")] +for zeile in sourcefolder: + tabelle.insert(zahl, (str(zahl), zeile)) + zahl += 1 + +# Open list in menu and let user choose one +ausgewaehlt = d.menu("Biddesehr:", width=xwidth, height=0, menu_height=ywidth, title="Such dir ne Datei", choices=tabelle) + +# Clean filename from leading .md for later construction of a headline +fn = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1]) + +sourcefile = glob.glob(sourcedir + fn + ".md") +targetfile = 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] " + fn + "*") +print("Sourcefile: ", sourcefile, "\nTargetfile: ", targetfile)