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

22
jrnl.py
View file

@ -1,20 +1,24 @@
#!/usr/bin/python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
import os
import tempfile
import parsedatetime.parsedatetime as pdt import parsedatetime.parsedatetime as pdt
import parsedatetime.parsedatetime_consts as pdc import parsedatetime.parsedatetime_consts as pdc
import subprocess
import re import re
import argparse import argparse
from datetime import datetime from datetime import datetime
import time import time
import json import json
import sys
config = { config = {
'journal': "/home/manuel/Dropbox/Notes/journal.txt", 'journal': "/Users/dedan/Dropbox/Notes/journal_neu.txt",
'editor': "subl -w",
'default_hour': 9, 'default_hour': 9,
'default_minute': 0, 'default_minute': 0,
'timeformat': "%Y-%m-%d %H:%M", 'timeformat': "%Y-%m-%d %H:%M",
'tagsymbols': '#@' 'tagsymbols': '@'
} }
class Entry: class Entry:
@ -198,6 +202,7 @@ class Journal:
self.sort() self.sort()
if __name__ == "__main__": if __name__ == "__main__":
print sys.argv
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments') 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"') 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('-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') reading.add_argument('-json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
args = parser.parse_args() args = parser.parse_args()
print args
# open journal # open journal
journal = Journal(config=config) journal = Journal(config=config)
@ -225,6 +231,14 @@ if __name__ == "__main__":
# No text? Query # No text? Query
if compose and not args.text: if compose and not args.text:
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: ") raw = raw_input("Compose Entry: ")
if raw: if raw:
args.text = [raw] args.text = [raw]