2021-11-15 12:43:30 +01:00
|
|
|
#!/usr/bin/python3
|
2021-11-20 18:19:59 +01:00
|
|
|
import sys, re, os, pg, datetime, locale, glob
|
2021-11-15 12:43:30 +01:00
|
|
|
from dialog import Dialog
|
|
|
|
|
|
|
|
## Initialize a dialog.Dialog instance
|
|
|
|
d = Dialog(dialog="dialog")
|
|
|
|
|
2021-11-20 18:19:59 +01:00
|
|
|
clear = "\x1b[2J\x1b[H"
|
2021-11-15 12:43:30 +01:00
|
|
|
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)
|
|
|
|
|
2021-11-20 18:19:59 +01:00
|
|
|
if ausgewaehlt[0] == "cancel":
|
|
|
|
sys.exit("Na, dann eben nicht...")
|
|
|
|
|
2021-11-15 12:43:30 +01:00
|
|
|
# Clean filename from leading .md for later construction of a headline
|
|
|
|
fn = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1])
|
|
|
|
|
2021-11-20 18:19:59 +01:00
|
|
|
sourcefile = str(glob.glob(sourcedir + fn + ".md")[0])
|
2021-11-15 12:43:30 +01:00
|
|
|
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 + "*")
|
2021-11-20 18:19:59 +01:00
|
|
|
targetfilelength = len(targetfile)
|
|
|
|
if targetfilelength >= 1:
|
|
|
|
targetfile = targetfile[targetfilelength - 1]
|
|
|
|
if not targetfile:
|
|
|
|
targetfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + fn
|
|
|
|
print(clear, "\nSourcefile: ", sourcefile, "\nTargetfile: ", targetfile)
|
|
|
|
|
|
|
|
# return sourcefile, targetfile
|