#!/usr/bin/python # GPL3.0 licensed # Developed by r3dwall # http://git.qwik.i2p/r3dwall/newday import sys import os # Input file t = 0 # Get command line options opts = {"help":0, "override":0, "output":0} for i, o in enumerate(sys.argv): if i == 1: t = o elif o == "-o": opts["output"] = sys.argv[i+1] elif o == "-y": opts["override"] = 1 elif o == "-h" or o == "--help": opts["help"] = 1 else: pass # Help message if opts["help"] or not t: print("Usage: ./newday_emacs.py ") print("Simple util developed in python to take a daily emacs org file and transform it into another one with the name 'today.org' with only things that were left undone for the day") print("-y | overwrite output file") print("-o | output file") print("-h | this help") sys.exit() # Locate file try: f1 = open(t, "r") except: print("File {} does not exist. For help type ./newday_emacs.py -h".format(t)) sys.exit() # Read file read = f1.readlines() f1.close() d = [] # Save lines with only undone tasks ([]), todos and metainfo from the beginning of the file for l in read: if "TODO" in l: d.append(l) elif "[ ]" in l: d.append(l) elif "#+" in l: d.append(l) else: pass # Write everything to today.org t = opts["output"] if opts["output"] != 0 else "today.org" if opts["override"]: pass elif t in os.listdir(): print("File exists. Use -y to overwrite.") sys.exit() # Transform d into string c = "" for e in d: if "TODO" in e or "#!" in e: c += "\n{}".format(e) else: c += e del d f2 = open(t, "w+") f2.write(c) f2.close()