From 9532d9a8f3bfc07e714ca827ebee938ea1481c1d Mon Sep 17 00:00:00 2001 From: lemon24 Date: Tue, 12 Oct 2021 16:27:25 +0300 Subject: [PATCH] Make the mark_as_read plugin mark entries as "don't care" (read+unimportant). Closes #260. --- CHANGES.rst | 7 ++++++- docs/plugins.rst | 2 +- src/reader/plugins/mark_as_read.py | 12 ++++++++++-- tests/test_plugins_mark_as_read.py | 20 ++++++++++++++++---- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index e7c22913..2bc535be 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,11 @@ Version 2.4 Unreleased +* Change :mod:`~reader.plugins.mark_as_read` to also + explicitly mark matching entries as unimportant, + similar to how the *don't care* web application button works. + (:issue:`260`) + Version 2.3 ----------- @@ -66,7 +71,7 @@ Released 2021-10-08 from the duplicates to the new entry. (:issue:`254`) -* In the web application, allow marking an entry as "don't care" +* In the web application, allow marking an entry as *don't care* (read + unimportant explicitly set by the user) with a single button. (:issue:`254`) * In the web application, show the entry read modified / important modified diff --git a/docs/plugins.rst b/docs/plugins.rst index 72fd193a..7119989e 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -46,7 +46,7 @@ For `built-in plugins`_, it is enough to use the plugin name (``reader.XYZ``). .. note:: - :func:`make_reader()` ignores the plugin environment variables. + :func:`make_reader` ignores the plugin environment variables. Experimental plugins diff --git a/src/reader/plugins/mark_as_read.py b/src/reader/plugins/mark_as_read.py index ce757ba7..f43c8a41 100644 --- a/src/reader/plugins/mark_as_read.py +++ b/src/reader/plugins/mark_as_read.py @@ -2,7 +2,11 @@ reader.mark_as_read ~~~~~~~~~~~~~~~~~~~ -Mark added entries of specific feeds as read if their title matches a regex. +.. module:: reader + :noindex: + +Mark added entries of specific feeds as read + unimportant +if their title matches a regex. To configure, set the ``make_reader_reserved_name('mark_as_read')`` (by default, ``.reader.mark_as_read``) @@ -13,6 +17,10 @@ } +.. versionchanged:: 2.4 + Explicitly mark matching entries as unimportant. + + .. todo:: Possible optimizations: @@ -62,7 +70,7 @@ def _mark_as_read(reader, entry, status): for pattern in patterns or (): if re.search(pattern, entry.title): - reader.mark_entry_as_read(entry) + reader._mark_entry_as_dont_care(entry) return diff --git a/tests/test_plugins_mark_as_read.py b/tests/test_plugins_mark_as_read.py index 63f1d784..c35b3c0f 100644 --- a/tests/test_plugins_mark_as_read.py +++ b/tests/test_plugins_mark_as_read.py @@ -3,6 +3,7 @@ import pytest from fakeparser import Parser +from utils import naive_datetime from utils import utc_datetime as datetime @@ -12,13 +13,21 @@ def test_regex_mark_as_read(make_reader): reader = make_reader(':memory:', plugins=['reader.mark_as_read']) + def get_entry_data(**kwargs): + return { + (e.id, e.read, e.read_modified, e.important, e.important_modified) + for e in reader.get_entries(**kwargs) + } + parser = Parser() reader._parser = parser one = parser.feed(1, datetime(2010, 1, 1)) parser.entry(1, 1, datetime(2010, 1, 1), title='match old') + reader._now = lambda: naive_datetime(2010, 1, 1) reader.add_feed(one) + reader.update_feeds() reader.set_feed_metadata_item(one, key, value) @@ -30,19 +39,22 @@ def test_regex_mark_as_read(make_reader): two = parser.feed(2, datetime(2010, 1, 2)) parser.entry(2, 3, datetime(2010, 1, 2), title='match other') + reader._now = lambda: naive_datetime(2010, 2, 1) reader.add_feed(two) reader.update_feeds() assert len(list(reader.get_entries())) == 4 - assert set((e.id, e.read) for e in reader.get_entries(read=True)) == { - (match_new.id, True), + assert get_entry_data(read=True) == { + (match_new.id, True, datetime(2010, 2, 1), False, datetime(2010, 2, 1)), } parser.entry(1, 3, datetime(2010, 1, 2), title='no match once again') + + reader._now = lambda: naive_datetime(2010, 3, 1) reader.update_feeds() - assert set((e.id, e.read) for e in reader.get_entries(read=True)) == { - (match_new.id, True), + assert get_entry_data(read=True) == { + (match_new.id, True, datetime(2010, 2, 1), False, datetime(2010, 2, 1)), }