mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
Create datecount plugin
This commit is contained in:
parent
c155bafa84
commit
654cc6f56a
3 changed files with 43 additions and 0 deletions
|
@ -3,11 +3,13 @@
|
|||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
from jrnl.plugins.datecount_exporter import DatecountExporter
|
||||
from .fancy_exporter import FancyExporter
|
||||
from .jrnl_importer import JRNLImporter
|
||||
from .json_exporter import JSONExporter
|
||||
from .markdown_exporter import MarkdownExporter
|
||||
from .tag_exporter import TagExporter
|
||||
from .datecount_exporter import DatecountExporter
|
||||
from .template_exporter import __all__ as template_exporters
|
||||
from .text_exporter import TextExporter
|
||||
from .xml_exporter import XMLExporter
|
||||
|
@ -17,6 +19,7 @@ __exporters = [
|
|||
JSONExporter,
|
||||
MarkdownExporter,
|
||||
TagExporter,
|
||||
DatecountExporter,
|
||||
TextExporter,
|
||||
XMLExporter,
|
||||
YAMLExporter,
|
||||
|
|
27
jrnl/plugins/datecount_exporter.py
Normal file
27
jrnl/plugins/datecount_exporter.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (C) 2012-2021 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
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."""
|
||||
|
||||
names = ["datecount"]
|
||||
extension = "datecount"
|
||||
|
||||
@classmethod
|
||||
def export_entry(cls, entry):
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def export_journal(cls, journal):
|
||||
"""Returns dates and their frequencies for an entire journal."""
|
||||
date_counts = get_date_counts(journal)
|
||||
if not date_counts:
|
||||
return "[No dates found in journal.]"
|
||||
result = "\n".join(f"{date} {count}" for date, count in date_counts.items())
|
||||
return result
|
|
@ -3,6 +3,19 @@
|
|||
# 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"""
|
||||
# Dates are normalized
|
||||
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."""
|
||||
|
|
Loading…
Add table
Reference in a new issue