Skip to content

Commit

Permalink
Make the mark_as_read plugin mark entries as "don't care" (read+unimp…
Browse files Browse the repository at this point in the history
…ortant).

Closes #260.
  • Loading branch information
lemon24 committed Oct 12, 2021
1 parent 6727276 commit 9532d9a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/reader/plugins/mark_as_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``)
Expand All @@ -13,6 +17,10 @@
}
.. versionchanged:: 2.4
Explicitly mark matching entries as unimportant.
.. todo::
Possible optimizations:
Expand Down Expand Up @@ -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


Expand Down
20 changes: 16 additions & 4 deletions tests/test_plugins_mark_as_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from fakeparser import Parser
from utils import naive_datetime
from utils import utc_datetime as datetime


Expand All @@ -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)
Expand All @@ -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)),
}


Expand Down

0 comments on commit 9532d9a

Please sign in to comment.