External editor can be used for composing by specifying the editor config option

This commit is contained in:
Stephan Gabler 2012-04-13 18:37:28 +02:00
parent 5b5570f41e
commit 04cc68a29a

24
jrnl.py
View file

@ -1,20 +1,24 @@
#!/usr/bin/python
#!/usr/bin/env python
# encoding: utf-8
import os
import tempfile
import parsedatetime.parsedatetime as pdt
import parsedatetime.parsedatetime_consts as pdc
import subprocess
import re
import argparse
from datetime import datetime
import time
import json
import sys
config = {
'journal': "/home/manuel/Dropbox/Notes/journal.txt",
'journal': "/Users/dedan/Dropbox/Notes/journal_neu.txt",
'editor': "subl -w",
'default_hour': 9,
'default_minute': 0,
'timeformat': "%Y-%m-%d %H:%M",
'tagsymbols': '#@'
'tagsymbols': '@'
}
class Entry:
@ -198,6 +202,7 @@ class Journal:
self.sort()
if __name__ == "__main__":
print sys.argv
parser = argparse.ArgumentParser()
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments')
composing.add_argument('-date', dest='date', help='Date, e.g. "yesterday at 5pm"')
@ -210,6 +215,7 @@ if __name__ == "__main__":
reading.add_argument('-n', dest='limit', default=None, metavar="N", help='Shows the last n entries matching the filter', nargs="?", type=int)
reading.add_argument('-json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
args = parser.parse_args()
print args
# open journal
journal = Journal(config=config)
@ -225,7 +231,15 @@ if __name__ == "__main__":
# No text? Query
if compose and not args.text:
raw = raw_input("Compose Entry: ")
if config['editor']:
tmpfile = os.path.join(tempfile.gettempdir(), "jrnl")
subprocess.call(config['editor'].split() + [tmpfile])
with open(tmpfile) as f:
raw = f.read()
os.remove(tmpfile)
else:
raw = raw_input("Compose Entry: ")
if raw:
args.text = [raw]
else: