Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable blocklist to match on individual paragraphs #60

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ All articles are recorded in a sqlite database.

### Advanced feature: blocklist

In some cases, you may wish to suppress articles from being posted, even though they would otherwise match. You can do so by writing a new function, `check`, and placing it in a file named `blocklist.py` in the configuration directory. `check` takes an Article (and so has access to its `outlet`, `title`, and `url`) and should return `true` for any article that should be skipped.
In some cases, you may wish to suppress articles from being posted, even though they would otherwise match. You can do so by writing two new functions, `check_article` and `check_paragraph`, and placing them in a file named `blocklist.py` in the configuration directory:
- `check_article` takes an Article (and so has access to its `outlet`, `title`, and `url`) and should return `True` for any article that should be skipped in its entirety.
- `check_paragraph` takes an Article and an individual matching paragraph and should return `True` for any paragraph that should be skipped (if other paragraphs match, the article will still be posted, but without the skipped paragraphs).

## Development

Expand Down
4 changes: 3 additions & 1 deletion trackthenews/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ def check_for_matches(self, http_session):
self.clean(http_session)
plaintext_grafs = self.plaintext.split("\n")

if blocklist_loaded and blocklist.check(self):
if blocklist_loaded and blocklist.check_article(self):
pass
else:
for graf in plaintext_grafs:
if any(word.lower() in graf.lower() for word in matchwords) or any(
word in graf for word in matchwords_case_sensitive
):
if blocklist_loaded and blocklist.check_paragraph(self, graf):
continue
self.matching_grafs.append(graf)

def prepare_images(self, square):
Expand Down
Loading