-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjournal.py
executable file
·42 lines (32 loc) · 1006 Bytes
/
journal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
#
# Append the date to a file and open it in an editor
#
# If $EDITOR isn't defined, use vi
#
# if file isn't specified, use ~/Dropbox/Documents/filename.txt
#
import argparse
import datetime
import os
import subprocess
DEFAULT_BASE = os.path.join(os.environ["HOME"], "Dropbox", "Documents")
parser = argparse.ArgumentParser(description='Make Journal Entry')
parser.add_argument('filename')
args = parser.parse_args()
if os.pathsep in args.filename:
filename = args.filename
else:
filename = os.path.join(DEFAULT_BASE, args.filename)
if "." not in filename:
filename = filename + '.txt'
print(filename)
with open(filename, "a") as filehandle:
filehandle.write("\n")
filehandle.write(datetime.date.strftime(datetime.datetime.now(), "%D"))
filehandle.write("\n")
filehandle.write("\n")
editor = os.getenv('EDITOR', 'vi')
if "vi" in editor:
editor = editor + " +\"go 999999999\" +start"
subprocess.call('%s %s' % (editor, filename), shell=True)