Merge pull request #86 from maebert/export-fix

Allows filtering the journal before exporting
This commit is contained in:
Manuel Ebert 2013-08-06 18:17:45 -07:00
commit 1ebbd46227
8 changed files with 88 additions and 9 deletions

View file

@ -1,7 +1,11 @@
Changelog
=========
### 1.4.2
### 1.5.0
* [Improved] Exporting, encrypting and displaying tags now takes your filter options into account. So you could export everything before May 2012: `jrnl -to 'may 2012' --export json`. Or encrypt all entries tagged with `@work` into a new journal: `jrnl @work --encrypt work_journal.txt`. Or display all tags of posts where Bob is also tagged: `jrnl @bob --tags`
#### 1.4.2
* [Fixed] Tagging works again
* Meta-info for PyPi updated
@ -10,7 +14,7 @@ Changelog
* [Improved] Unifies encryption between Python 2 and 3. If you have problems reading encrypted journals afterwards, first decrypt your journal with the __old__ jrnl version (install with `pip install jrnl==1.3.1`, then `jrnl --decrypt`), upgrade jrnl (`pip install jrnl --upgrade`) and encrypt it again (`jrnl --encrypt`).
### 1.3.2
#### 1.3.2
* [Improved] Everything that is not direct output of jrnl will be written stderr to improve integration

View file

@ -1,4 +1,4 @@
2013-06-09 15:39 I have an @idea:
2013-04-09 15:39 I have an @idea:
(1) write a command line @journal software
(2) ???
(3) PROFIT!

View file

@ -0,0 +1,22 @@
Feature: Expoting a Journal
Scenario: Exporting to json
Given we use the config "tags.json"
When we run "jrnl --export json"
Then we should get no error
and the output should be parsable as json
and "entries" in the json output should have 2 elements
and "tags" in the json output should contain "@idea"
and "tags" in the json output should contain "@journal"
and "tags" in the json output should contain "@dan"
Scenario: Exporting using filters should only export parts of the journal
Given we use the config "tags.json"
When we run "jrnl -to 'may 2013' --export json"
# Then we should get no error
Then the output should be parsable as json
and "entries" in the json output should have 1 element
and "tags" in the json output should contain "@idea"
and "tags" in the json output should contain "@journal"
and "tags" in the json output should not contain "@dan"

View file

@ -8,6 +8,20 @@ try:
except ImportError:
from cStringIO import StringIO
def _parse_args(command):
nargs=[]
concats = []
for a in command.split()[1:]:
if a.startswith("'"):
concats.append(a.strip("'"))
elif a.endswith("'"):
concats.append(a.strip("'"))
nargs.append(u" ".join(concats))
concats = []
else:
nargs.append(a)
return nargs
def read_journal(journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file:
config = json.load(config_file)
@ -34,14 +48,14 @@ def set_config(context, config_file):
@when('we run "{command}" and enter "{inputs}"')
def run_with_input(context, command, inputs=None):
text = inputs or context.text
args = command.split()[1:]
args = _parse_args(command)
buffer = StringIO(text.strip())
jrnl.util.STDIN = buffer
jrnl.cli(args)
@when('we run "{command}"')
def run(context, command):
args = command.split()[1:]
args = _parse_args(command)
jrnl.cli(args or None)
@ -49,6 +63,33 @@ def run(context, command):
def no_error(context):
assert context.failed is False
@then('the output should be parsable as json')
def check_output_json(context):
out = context.stdout_capture.getvalue()
assert json.loads(out)
@then('"{field}" in the json output should have {number:d} elements')
@then('"{field}" in the json output should have 1 element')
def check_output_field(context, field, number=1):
out = context.stdout_capture.getvalue()
out_json = json.loads(out)
assert field in out_json
assert len(out_json[field]) == number
@then('"{field}" in the json output should not contain "{key}"')
def check_output_field_not_key(context, field, key):
out = context.stdout_capture.getvalue()
out_json = json.loads(out)
assert field in out_json
assert key not in out_json[field]
@then('"{field}" in the json output should contain "{key}"')
def check_output_field_key(context, field, key):
out = context.stdout_capture.getvalue()
out_json = json.loads(out)
assert field in out_json
assert key in out_json[field]
@then('the output should be')
def check_output(context):
text = context.text.strip().splitlines()

View file

@ -10,3 +10,13 @@ Feature: Tagging
@journal : 1
@dan : 1
"""
Scenario: Filtering journals should also filter tags
Given we use the config "tags.json"
When we run "jrnl -from 'may 2013' --tags"
Then we should get no error
and the output should be
"""
@idea : 1
@dan : 1
"""

View file

@ -54,6 +54,7 @@ class Journal(object):
consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
self.dateparse = pdt.Calendar(consts)
self.key = None # used to decrypt and encrypt the journal
self.search_tags = None # Store tags we're highlighting
journal_txt = self.open()
self.entries = self.parse(journal_txt)

View file

@ -7,7 +7,7 @@ jrnl is a simple journal application for your command line.
"""
__title__ = 'jrnl'
__version__ = '1.4.2'
__version__ = '1.5.0'
__author__ = 'Manuel Ebert'
__license__ = 'MIT License'
__copyright__ = 'Copyright 2013 Manuel Ebert'

View file

@ -176,14 +176,15 @@ def cli(manual_args=None):
entry.starred = args.star
util.prompt("[Entry added to {0} journal]".format(journal_name))
journal.write()
# Reading mode
elif not mode_export:
else:
journal.filter(tags=args.text,
start_date=args.start_date, end_date=args.end_date,
strict=args.strict,
short=args.short)
journal.limit(args.limit)
# Reading mode
if not mode_export:
print(journal.pprint())
# Various export modes