import datetime import re import os import subprocess import sys import unidecode TEMPLATE = """{headline} :date: {date} :slug: {slug} :tags: new :category: new :authors: Markus Demleitner :lang: en :status: published Lorem ipsum """ def main(): if len(sys.argv)<2: sys.exit("Usage: {} [title words]".format(sys.argv[0])) headline = " ".join(sys.argv[1:]) slug = re.sub(r"[^\w]+", "-", unidecode.unidecode(headline)).lower() now = datetime.datetime.utcnow() desambig = "" while True: destname = "content/{}{}.rst".format(now.strftime("%Y-%m-%d"), desambig) if not os.path.exists(destname): break desambig = str(int(desambig or "0")-1) with open(destname, "w", encoding="utf-8") as f: f.write(TEMPLATE.format( headline = headline+"\n"+("="*len(headline)), date = now.isoformat(), slug = slug)) subprocess.check_call(["svn", "add", destname]) subprocess.check_call(["build-one", destname]) # the webbrowser module doesn't work well with luakit at this point. # I'm hardcoding things. f = open("/dev/null", "wb") subprocess.Popen(["luakit", f"http://blog/{slug}.html"], stdout=f, stderr=f) print(f"build-one {destname}") os.execlp("gvim", "gvim", destname) if __name__=="__main__": main()