mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Adds tag search, closes #16
This commit is contained in:
parent
4a52da5469
commit
eab92dbb23
3 changed files with 21 additions and 1 deletions
|
@ -5,6 +5,7 @@ Changelog
|
|||
|
||||
* Adds --encrypt and --decrypt to encrypt / descrypt existing journal files
|
||||
* Adds markdown export (kudos to dedan)
|
||||
* Adds tag export
|
||||
|
||||
### 0.2.1
|
||||
|
||||
|
|
|
@ -136,6 +136,14 @@ Can do:
|
|||
|
||||
Why not create a beautiful [timeline](http://timeline.verite.co/) of your journal?
|
||||
|
||||
### Tag export
|
||||
|
||||
With
|
||||
|
||||
jrnl --tags
|
||||
|
||||
you'll get a list of all tags you used in your journal, sorted by most frequent. Tags occuring several times in the same entry are only counted as one.
|
||||
|
||||
### Markdown export
|
||||
|
||||
jrnl --markdown
|
||||
|
|
13
jrnl.py
13
jrnl.py
|
@ -347,6 +347,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)
|
||||
|
||||
exporting = parser.add_argument_group('Export / Import', 'Options for transmogrifying your journal')
|
||||
exporting.add_argument('--tags', dest='tags', action="store_true", help='Returns a list of all tags and number of occurences')
|
||||
exporting.add_argument('--json', dest='json', action="store_true", help='Returns a JSON-encoded version of the Journal')
|
||||
exporting.add_argument('--markdown', dest='markdown', action="store_true", help='Returns a Markdown-formated version of the Journal')
|
||||
exporting.add_argument('--encrypt', dest='encrypt', action="store_true", help='Encrypts your existing journal with a new password')
|
||||
|
@ -357,7 +358,7 @@ if __name__ == "__main__":
|
|||
# Guess mode
|
||||
compose = True
|
||||
export = False
|
||||
if args.json or args.decrypt or args.encrypt or args.markdown:
|
||||
if args.json or args.decrypt or args.encrypt or args.markdown or args.tags:
|
||||
compose = False
|
||||
export = True
|
||||
elif args.start_date or args.end_date or args.limit or args.strict:
|
||||
|
@ -398,6 +399,16 @@ if __name__ == "__main__":
|
|||
journal.limit(args.limit)
|
||||
print(journal)
|
||||
|
||||
elif args.tags: # get all tags
|
||||
tags = {}
|
||||
for entry in journal.entries:
|
||||
for tag in entry.tags:
|
||||
tags[tag] = tags.get(tag, 0) + 1
|
||||
tags = [(n, tag) for tag, n in tags.viewitems()]
|
||||
tags.sort(reverse=True)
|
||||
for n, tag in tags:
|
||||
print "%-20s : %d" % (tag, n)
|
||||
|
||||
elif args.json: # export to json
|
||||
print(journal.to_json())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue