#!/usr/bin/env python3 import sys, os, uuid, shutil, subprocess, 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 targetdir = os.path.expanduser("~/www/i21k.de/posts/") fileending = "" # call favorite editor with filename to write the text def edit(headline): editor = os.getenv("EDITOR") if not editor: editor = "vim" subprocess.call([editor, headline]) return headline # Parse arguments "--html", "--stdout" 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"] outfile = "" args = sys.argv myname = args.pop(0) for wish in optwords: if args.count(wish): if wish == "--html": fileending = ".html" args.pop(args.index(wish)) if wish == "--stdout": outfile = sys.stdout args.pop(args.index(wish)) if len(args) == 1: headline = args[0] elif len(args) == 0: headline = input("Please enter a headline: ") elif len(args) > 1: sys.exit("Too much or wrong parameters:\n" + myname + ' [--html] [--stdout] ["Some Topic"] ') # The headline should be the theme of the text. We edit a .md-file headlinemd = headline + ".md" # Prepend an hourly tinestamp to the later name of the file creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") # generate a more precise ctime to be included in the resulting webpage creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") # This is informal asking yes/no for editing the text if outfile != sys.stdout: new_file_name = targetdir + creationtime + " " + headline + fileending else: new_file_name = "STDOUT" print("You will edit now: ", headlinemd, "\nOutputfile= ", new_file_name) a = input("Press to continue or to stop: ") edit(headlinemd) # Set ouput to stdout, if requested. Caution, the prompts of this script go there, too, # be careful with copy & paste if outfile != sys.stdout: html_out_file = open(new_file_name, "w") else: html_out_file = outfile # The head of the output. Strip path from myname head1 = ( '\n\ \n' + headline + '\n\ \n\ \n\ \n\ ' ) # Some fancy css for minimalistic terminal style styles = "