From 5219600aa03ff9709ebdd8e845f5550feedb9ed6 Mon Sep 17 00:00:00 2001 From: karimpwnz Date: Tue, 5 Jan 2021 00:08:38 +0200 Subject: [PATCH] Move get_date_counts into DateCountExporter; misc changes --- jrnl/plugins/datecount_exporter.py | 10 +++++++--- jrnl/plugins/util.py | 12 ------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/jrnl/plugins/datecount_exporter.py b/jrnl/plugins/datecount_exporter.py index 0d3e6057..ff9cef52 100644 --- a/jrnl/plugins/datecount_exporter.py +++ b/jrnl/plugins/datecount_exporter.py @@ -2,13 +2,13 @@ # encoding: utf-8 # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +from collections import Counter from .text_exporter import TextExporter -from .util import get_date_counts class DatecountExporter(TextExporter): - """This Exporter can lists the tags for entries and journals, exported as a plain text file.""" + """This Exporter lists dates and their respective counts, for heatingmapping etc.""" names = ["datecount"] extension = "datecount" @@ -20,6 +20,10 @@ class DatecountExporter(TextExporter): @classmethod def export_journal(cls, journal): """Returns dates and their frequencies for an entire journal.""" - date_counts = get_date_counts(journal) + date_counts = Counter() + for entry in journal.entries: + # entry.date.date() gets date without time + date = str(entry.date.date()) + date_counts[date] += 1 result = "\n".join(f"{date}, {count}" for date, count in date_counts.items()) return result diff --git a/jrnl/plugins/util.py b/jrnl/plugins/util.py index 38d3e9f0..04159ca4 100644 --- a/jrnl/plugins/util.py +++ b/jrnl/plugins/util.py @@ -3,18 +3,6 @@ # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html -from collections import Counter - - -def get_date_counts(journal): - """Returns a collections.Counter object containing date counts""" - date_counts = Counter() - for entry in journal.entries: - # entry.date.date() gets date without time - date = str(entry.date.date()) - date_counts[date] += 1 - return date_counts - def get_tags_count(journal): """Returns a set of tuples (count, tag) for all tags present in the journal."""