diff options
Diffstat (limited to 'scripts/journal-note')
-rwxr-xr-x | scripts/journal-note | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/scripts/journal-note b/scripts/journal-note index 211aa72..60ab9c0 100755 --- a/scripts/journal-note +++ b/scripts/journal-note @@ -17,6 +17,7 @@ import optparse import os +import re import subprocess import sys import tempfile @@ -49,12 +50,6 @@ class App(object): return p.parse_args() - def tempfile(self, dirname, content): - fd, name = tempfile.mkstemp(dir=dirname) - os.write(fd, content) - os.close(fd) - return name - def main(self): commands = { 'new': self.new_entry, @@ -75,17 +70,37 @@ class App(object): def new_entry(self, args, opts): if not args: raise AppException('Usage: journal-note new TITLE') + + for i in range(1000): + name = os.path.join(opts.base, 'drafts', '%d.mdwn' % i) + if not os.path.exists(name): + break + else: + raise AppException('ERROR: too many existing drafts') + values = { 'title': args[0], 'date': time.strftime('%Y-%m-%d %H:%M') } - - name = self.tempfile(self.drafts(opts), template % values) - print name + f = open(name, 'w') + f.write(template % values) + f.close() def list_entries(self, args, opts): - for name in os.listdir(self.drafts(opts)): - print name + drafts = self.drafts(opts) + for name in os.listdir(drafts): + if name.endswith('.mdwn'): + f = open(os.path.join(drafts, name)) + for line in f: + m = re.match('\[\[!meta title="(?P<title>.*)("\]\])$', + line) + if m: + title = m.group('title') + break + else: + title = 'unknown title' + f.close() + print name[:-len('.mdwn')], title def edit_entry(self, args, opts): if not args: |