diff --git a/CHANGELOG.md b/CHANGELOG.md index 2233df16..de3b4277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c50d19d2..250f6c2b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/jrnl.py b/jrnl.py index 27263c51..76f4b8ee 100755 --- a/jrnl.py +++ b/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())