-
Notifications
You must be signed in to change notification settings - Fork 0
/
brainstorm
executable file
·73 lines (60 loc) · 2.28 KB
/
brainstorm
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import argparse, datetime, os
HOME_DIR = os.path.join(os.path.expanduser('~'), 'brainstorms')
FN_FORMAT = 'brainstorm_%s.txt'
class BrainstormManager(object):
def __init__(self):
self.date = None;
if not os.path.isdir(HOME_DIR):
os.mkdir(HOME_DIR)
def create_or_open(self):
date = datetime.datetime.today().strftime('%m_%d_%Y')
self.open(date)
def read(self):
dates = []
otherFiles = []
for fn in [f for f in os.listdir(HOME_DIR) if not f.startswith('.')]:
try:
dates.append(datetime.datetime.strptime(
fn, 'brainstorm_%m_%d_%Y.txt').date())
except Exception, e:
if 'brainstorm' in fn:
otherFiles.append(fn)
dates.sort(reverse=True)
today = datetime.datetime.today().date()
if today in dates:
dates.remove(today)
if len(otherFiles):
print "Named brainstorms:"
print '--------------'
for i, name in enumerate(otherFiles):
print '0%s: %s' % (i+1, name)
print ''
print "Daily brainstorms: "
print '--------------'
for i, date in enumerate(dates):
print '%s: %s' % (i+1, date.strftime('%a %b %d, %Y'))
print ""
resp = raw_input("Which file would you like to open? ")
try:
if resp == "":
self.open(dates[0].strftime('%m_%d_%Y'))
elif resp.startswith('0') and int(resp) - 1 < len(otherFiles):
self._open(otherFiles[int(resp)-1])
elif int(resp) - 1 < len(dates):
self.open(dates[int(resp)-1].strftime('%m_%d_%Y'))
except Exception as e:
print "invalid entry '%s'" % resp
def _open(self, fn):
os.system('vim %s/%s' % (HOME_DIR, fn))
def open(self, fn):
self._open("brainstorm_%s.txt" % fn)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Brainstorm Manager")
parser.add_argument('-p', '--previous', dest='p', action='store_true', help='Open the previous log')
args = parser.parse_args()
bs = BrainstormManager()
if args.p:
bs.read()
else:
bs.create_or_open()