Skip to content

Commit

Permalink
Enable blocklist to match on individual paragraphs
Browse files Browse the repository at this point in the history
This allows us to take better control over false positives.
  • Loading branch information
eloquence committed May 15, 2024
1 parent 34dea4a commit cd5ec61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit cd5ec61

Please sign in to comment.