Adds tag search, closes #16

This commit is contained in:
Manuel Ebert 2012-04-24 12:05:17 +02:00
parent 632add24f9
commit ae57eb9d77
3 changed files with 21 additions and 1 deletions

View file

@ -5,6 +5,7 @@ Changelog
* Adds --encrypt and --decrypt to encrypt / descrypt existing journal files * Adds --encrypt and --decrypt to encrypt / descrypt existing journal files
* Adds markdown export (kudos to dedan) * Adds markdown export (kudos to dedan)
* Adds tag export
### 0.2.1 ### 0.2.1

View file

@ -136,6 +136,14 @@ Can do:
Why not create a beautiful [timeline](http://timeline.verite.co/) of your journal? 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 ### Markdown export
jrnl --markdown jrnl --markdown

13
jrnl.py
View file

@ -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) 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 = 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('--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('--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') 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 # Guess mode
compose = True compose = True
export = False 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 compose = False
export = True export = True
elif args.start_date or args.end_date or args.limit or args.strict: 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) journal.limit(args.limit)
print(journal) 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 elif args.json: # export to json
print(journal.to_json()) print(journal.to_json())