You can now filter the author

This commit is contained in:
2023-01-30 01:21:16 +01:00
parent 10e335e6e2
commit 9a90385fae
7 changed files with 77 additions and 19 deletions

View File

@ -38,13 +38,17 @@ def should_be_skipped(custom_reader: Reader, entry: Entry) -> bool:
feed: Feed = entry.feed
blacklist_title: str = str(custom_reader.get_tag(feed, "blacklist_title", ""))
blacklist_summary: str = str(custom_reader.get_tag(feed, "blacklist_summary", ""))
# blacklist_content: str = str(custom_reader.get_tag(feed, "blacklist_content", ""))
# TODO: Fix content
# TODO: Check author
blacklist_content: str = str(custom_reader.get_tag(feed, "blacklist_content", ""))
blacklist_author: str = str(custom_reader.get_tag(feed, "blacklist_author", ""))
# TODO: Also add support for entry_text
if entry.title and blacklist_title and is_word_in_text(blacklist_title, entry.title):
return True
elif entry.summary and blacklist_summary and is_word_in_text(blacklist_summary, entry.summary):
return True
elif entry.author and blacklist_author and is_word_in_text(blacklist_author, entry.author):
return True
elif entry.content:
if entry.content[0].value and blacklist_content and is_word_in_text(blacklist_content, entry.content[0].value):
return True
return False

View File

@ -38,12 +38,16 @@ def should_be_sent(custom_reader: Reader, entry: Entry) -> bool:
feed: Feed = entry.feed
whitelist_title: str = str(custom_reader.get_tag(feed, "whitelist_title", ""))
whitelist_summary: str = str(custom_reader.get_tag(feed, "whitelist_summary", ""))
# whitelist_content: str = get_whitelist_content(custom_reader, feed)
# TODO: Fix content
# TODO: Check author
whitelist_content: str = str(custom_reader.get_tag(feed, "whitelist_content", ""))
whitelist_author: str = str(custom_reader.get_tag(feed, "whitelist_author", ""))
if entry.title and whitelist_title and is_word_in_text(whitelist_title, entry.title):
return True
elif entry.summary and whitelist_summary and is_word_in_text(whitelist_summary, entry.summary):
return True
elif entry.author and whitelist_author and is_word_in_text(whitelist_author, entry.author):
return True
elif entry.content:
if entry.content[0].value and whitelist_content and is_word_in_text(whitelist_content, entry.content[0].value):
return True
return False

View File

@ -113,14 +113,16 @@ async def post_set_whitelist(
whitelist_title: str = Form(None),
whitelist_summary: str = Form(None),
whitelist_content: str = Form(None),
whitelist_author: str = Form(None),
feed_url: str = Form(),
):
"""Set what the whitelist should be sent, if you have this set only words in the whitelist will be sent.
Args:
whitelist_title: Whitelisted words for when checking the title.
whitelist_summary: Whitelisted words for when checking the title.
whitelist_content: Whitelisted words for when checking the title.
whitelist_summary: Whitelisted words for when checking the summary.
whitelist_content: Whitelisted words for when checking the content.
whitelist_author: Whitelisted words for when checking the author.
feed_url: The feed we should set the whitelist for.
"""
clean_feed_url: str = feed_url.strip()
@ -130,6 +132,8 @@ async def post_set_whitelist(
reader.set_tag(clean_feed_url, "whitelist_summary", whitelist_summary) # type: ignore
if whitelist_content:
reader.set_tag(clean_feed_url, "whitelist_content", whitelist_content) # type: ignore
if whitelist_author:
reader.set_tag(clean_feed_url, "whitelist_author", whitelist_author) # type: ignore
return RedirectResponse(url=f"/feed/?feed_url={urllib.parse.quote(clean_feed_url)}", status_code=303)
@ -148,6 +152,7 @@ async def get_whitelist(feed_url: str, request: Request):
whitelist_title: str = str(reader.get_tag(feed, "whitelist_title", ""))
whitelist_summary: str = str(reader.get_tag(feed, "whitelist_summary", ""))
whitelist_content: str = str(reader.get_tag(feed, "whitelist_content", ""))
whitelist_author: str = str(reader.get_tag(feed, "whitelist_author", ""))
context = {
"request": request,
@ -155,6 +160,7 @@ async def get_whitelist(feed_url: str, request: Request):
"whitelist_title": whitelist_title,
"whitelist_summary": whitelist_summary,
"whitelist_content": whitelist_content,
"whitelist_author": whitelist_author,
}
return templates.TemplateResponse("whitelist.html", context)
@ -164,6 +170,7 @@ async def post_set_blacklist(
blacklist_title: str = Form(None),
blacklist_summary: str = Form(None),
blacklist_content: str = Form(None),
blacklist_author: str = Form(None),
feed_url: str = Form(),
):
"""Set the blacklist, if this is set we will check if words are in the title, summary or content
@ -173,15 +180,18 @@ async def post_set_blacklist(
blacklist_title: Blacklisted words for when checking the title.
blacklist_summary: Blacklisted words for when checking the summary.
blacklist_content: Blacklisted words for when checking the content.
blacklist_author: Blacklisted words for when checking the author.
feed_url: What feed we should set the blacklist for.
"""
clean_feed_url = feed_url.strip()
clean_feed_url: str = feed_url.strip()
if blacklist_title:
reader.set_tag(clean_feed_url, "blacklist_title", blacklist_title) # type: ignore
if blacklist_summary:
reader.set_tag(clean_feed_url, "blacklist_summary", blacklist_summary) # type: ignore
if blacklist_content:
reader.set_tag(clean_feed_url, "blacklist_content", blacklist_content) # type: ignore
if blacklist_author:
reader.set_tag(clean_feed_url, "blacklist_author", blacklist_author) # type: ignore
return RedirectResponse(url=f"/feed/?feed_url={urllib.parse.quote(feed_url)}", status_code=303)
@ -194,6 +204,7 @@ async def get_blacklist(feed_url: str, request: Request):
blacklist_title: str = str(reader.get_tag(feed, "blacklist_title", ""))
blacklist_summary: str = str(reader.get_tag(feed, "blacklist_summary", ""))
blacklist_content: str = str(reader.get_tag(feed, "blacklist_content", ""))
blacklist_author: str = str(reader.get_tag(feed, "blacklist_author", ""))
context = {
"request": request,
@ -201,6 +212,7 @@ async def get_blacklist(feed_url: str, request: Request):
"blacklist_title": blacklist_title,
"blacklist_summary": blacklist_summary,
"blacklist_content": blacklist_content,
"blacklist_author": blacklist_author,
}
return templates.TemplateResponse("blacklist.html", context)

View File

@ -46,15 +46,22 @@
value="{% if blacklist_summary %}
{{- blacklist_summary -}}
{% endif %}"/>
<label for="blacklist_content" class="col-sm-6 col-form-label">Blacklist - Content (Not implemented yet)</label>
<label for="blacklist_content" class="col-sm-6 col-form-label">Blacklist - Content</label>
<input name="blacklist_content"
type="text"
class="form-control bg-dark border-dark text-muted"
id="blacklist_content"
value="{% if blacklist_content %}
{{- blacklist_content -}}
{% endif %}"
disabled/>
{% endif %}"/>
<label for="blacklist_author" class="col-sm-6 col-form-label">Blacklist - Author</label>
<input name="blacklist_author"
type="text"
class="form-control bg-dark border-dark text-muted"
id="blacklist_author"
value="{% if blacklist_author %}
{{- blacklist_author -}}
{% endif %}"/>
</div>
</div>
<!-- Add a hidden feed_url field to the form -->

View File

@ -46,15 +46,22 @@
value="{% if whitelist_summary %}
{{- whitelist_summary -}}
{% endif %}"/>
<label for="whitelist_content" class="col-sm-6 col-form-label">Whitelist - Content (Not implemented yet)</label>
<label for="whitelist_content" class="col-sm-6 col-form-label">Whitelist - Content</label>
<input name="whitelist_content"
type="text"
class="form-control bg-dark border-dark text-muted"
id="whitelist_content"
value="{% if whitelist_content %}
{{- whitelist_content -}}
{% endif %}"
disabled/>
{% endif %}"/>
<label for="whitelist_author" class="col-sm-6 col-form-label">Whitelist - Author</label>
<input name="whitelist_author"
type="text"
class="form-control bg-dark border-dark text-muted"
id="whitelist_author"
value="{% if whitelist_author %}
{{- whitelist_author -}}
{% endif %}"/>
</div>
</div>
<!-- Add a hidden feed_url field to the form -->

View File

@ -86,9 +86,21 @@ def test_should_be_skipped() -> None:
assert should_be_skipped(reader, first_entry[0]) is False
reader.set_tag(feed, "blacklist_content", "ffdnfdnfdnfdnfdndfn") # type: ignore
# TODO: This is not impelemented yet
assert should_be_skipped(reader, first_entry[0]) is True
reader.delete_tag(feed, "blacklist_content")
assert should_be_skipped(reader, first_entry[0]) is False
reader.set_tag(feed, "blacklist_content", "åäö") # type: ignore
assert should_be_skipped(reader, first_entry[0]) is False
reader.delete_tag(feed, "blacklist_content")
assert should_be_skipped(reader, first_entry[0]) is False
# TODO: Also add support for entry_text
reader.set_tag(feed, "blacklist_author", "TheLovinator") # type: ignore
assert should_be_skipped(reader, first_entry[0]) is True
reader.delete_tag(feed, "blacklist_author")
assert should_be_skipped(reader, first_entry[0]) is False
reader.set_tag(feed, "blacklist_author", "åäö") # type: ignore
assert should_be_skipped(reader, first_entry[0]) is False
reader.delete_tag(feed, "blacklist_author")
assert should_be_skipped(reader, first_entry[0]) is False

View File

@ -86,9 +86,21 @@ def test_should_be_sent() -> None:
assert should_be_sent(reader, first_entry[0]) is False
reader.set_tag(feed, "whitelist_content", "ffdnfdnfdnfdnfdndfn") # type: ignore
# TODO: This is not impelemented yet
assert should_be_sent(reader, first_entry[0]) is True
reader.delete_tag(feed, "whitelist_content")
assert should_be_sent(reader, first_entry[0]) is False
reader.set_tag(feed, "whitelist_content", "åäö") # type: ignore
assert should_be_sent(reader, first_entry[0]) is False
reader.delete_tag(feed, "whitelist_content")
assert should_be_sent(reader, first_entry[0]) is False
# TODO: Also add support for entry_text
reader.set_tag(feed, "whitelist_author", "TheLovinator") # type: ignore
assert should_be_sent(reader, first_entry[0]) is True
reader.delete_tag(feed, "whitelist_author")
assert should_be_sent(reader, first_entry[0]) is False
reader.set_tag(feed, "whitelist_author", "åäö") # type: ignore
assert should_be_sent(reader, first_entry[0]) is False
reader.delete_tag(feed, "whitelist_author")
assert should_be_sent(reader, first_entry[0]) is False