Threats Watcher¶
The functions of threats_watcher.core, taken from their docstrings.
threats_watcher.core
¶
extract_entities_and_threats(title)
¶
Extract and clean entities and threats from title using NER model.
start_scheduler()
¶
Launch planning tasks in background:
- Fire main_watch every 30 minutes
- Fire cleanup every day at 8 am
- Fire weekly summary based on settings configuration
cleanup()
¶
Remove words with a creation date greater than 30 days.
main_watch()
¶
Main function:
- close_old_connections()
- load_feeds()
- fetch_last_posts(settings.POSTS_DEPTH)
- tokenize_count_urls()
- remove_banned_words()
- focus_five_letters()
- focus_on_top(settings.WORDS_OCCURRENCE)
- send_threats_watcher_notifications()
get_confidence_score(confidence)
¶
Converts a confidence level (1, 2 or 3) to a percentage.
load_feeds()
¶
Load feeds.
fetch_last_posts(nb_max_post)
¶
Fetch the nb last posts for each feed (non-Bluesky) .
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nb_max_post
|
The deepness of the search on each feed. |
required |
tokenize_count_urls()
¶
For each title of the last 30 days: NER and threat extraction (once per title, the entities are kept), then the count of occurrences and the URLs. The job counts titles, titles_analyzed and titles_cached.
remove_banned_words()
¶
Clean the posts for specific patterns: BannedWord, then english + french common words.
focus_five_letters()
¶
Focus on 5 letters long words.
focus_on_top(words_occurrence)
¶
Keep the words seen at least words_occurrence times in the feeds, trigger the breaking news over the threshold, and
write the AI summary of the new or updated words.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
words_occurrence
|
Word occurrence in feeds. |
required |
get_pre_redirect_domain(url)
¶
Retrieves the domain of the URL before the redirect.
get_normalized_domain(url)
¶
Extracts and normalizes the domain from a URL without a network query (for Source objects).
reliability_score()
¶
Calculates the reliability score for each TrendyWord by scanning its associated PostUrls.
send_threats_watcher_notifications(content)
¶
Notify the Threats Watcher events: the type comes from the content. Slack, Citadel and TheHive follow the Notifications tab; the e-mail goes to the subscribers who ticked it and asked for this kind.
normalize_text(text)
¶
Lower case, without accents: 'Électricité' and 'electricite' are the same word.
match_rule(rule, text, normalized=False)
¶
The words of the rule found in text, or None when the article does not match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
anything with all_of, any_of, exceptions and whole_words. |
required | |
text
|
title and content of the article. |
required | |
normalized
|
|
False
|
Returns:
| Type | Description |
|---|---|
|
the matched words (all of |
match_keyword(keyword, text, normalized=False)
¶
The words of a monitored keyword found in text (its name when it is a single word), or None.
record_keyword_hit(keyword, title, link, words)
¶
Keep the article that a rule matched, to be reviewed.
Returns:
| Type | Description |
|---|---|
|
the new KeywordHit, or None when this article was already kept for this keyword. |
notify_keyword_rule_hit(hit)
¶
Tell the channels that an article matched a keyword rule. A channel that fails does not stop the next ones.