add neworgday.py
This commit is contained in:
parent
48f4d2ab3b
commit
a318eef3ad
|
@ -1,3 +1,7 @@
|
||||||
# newday
|
# Simple tool to generate a `today.org` file based on the unfinished TODO's of another orgfile
|
||||||
|
|
||||||
Tool to create a new day in orgmode
|
I use emacs' orgmode to manage my tasks. Everyday I needed to create another orgfile for the next day. With this tool I can automatically create the file and remove the already done tasks.
|
||||||
|
|
||||||
|
Use `./neworgday.py -h` for help.
|
||||||
|
|
||||||
|
License: GPL3.0
|
||||||
|
|
91
neworgday.py
Executable file
91
neworgday.py
Executable file
|
@ -0,0 +1,91 @@
|
||||||
|
#!/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 <input_file> <options>")
|
||||||
|
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()
|
Reference in New Issue
Block a user