diff --git a/bin/packages/Term.py b/bin/packages/Term.py index 245296ae..5bd91cd0 100755 --- a/bin/packages/Term.py +++ b/bin/packages/Term.py @@ -374,6 +374,9 @@ def get_term_tags(term_uuid): def get_term_mails(term_uuid): return list(r_serv_term.smembers('tracker:mail:{}'.format(term_uuid))) +def get_term_webhook(term_uuid): + return list(r_serv_term.hget('tracker:webhook:{}'.format(term_uuid))) + def add_tracked_item(term_uuid, item_id, item_date): # track item r_serv_term.sadd('tracker:item:{}:{}'.format(term_uuid, item_date), item_id) diff --git a/bin/trackers/Tracker_Term.py b/bin/trackers/Tracker_Term.py index a0986bdf..622aad2a 100755 --- a/bin/trackers/Tracker_Term.py +++ b/bin/trackers/Tracker_Term.py @@ -13,6 +13,8 @@ import os import sys import time import signal +import requests + sys.path.append(os.environ['AIL_BIN']) ################################## @@ -24,21 +26,24 @@ from packages.Item import Item from packages import Term from lib import Tracker - class TimeoutException(Exception): pass + + def timeout_handler(signum, frame): raise TimeoutException + + signal.signal(signal.SIGALRM, timeout_handler) class Tracker_Term(AbstractModule): - mail_body_template = "AIL Framework,\nNew occurrence for tracked term: {}\nitem id: {}\nurl: {}{}" """ Tracker_Term module for AIL framework """ + def __init__(self): super(Tracker_Term, self).__init__() @@ -56,7 +61,6 @@ class Tracker_Term(AbstractModule): self.redis_logger.info(f"Module: {self.module_name} Launched") - def compute(self, item_id): # refresh Tracked term if self.last_refresh_word < Term.get_tracked_term_last_updated_by_type('word'): @@ -88,7 +92,7 @@ class Tracker_Term(AbstractModule): if dict_words_freq: # create token statistics - #for word in dict_words_freq: + # for word in dict_words_freq: # Term.create_token_statistics(item_date, word, dict_words_freq[word]) item_source = item.get_source() @@ -135,8 +139,14 @@ class Tracker_Term(AbstractModule): print(f'S print(item_content)end Mail {mail_subject}') NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body) + webhook_to_post = Term.get_term_webhook(term_uuid) + if webhook_to_post: + request_body = dict({"itemId": item_id, "url": self.full_item_url, "type": "Term", "term": term}) + r = requests.post(webhook_to_post, data=request_body) + if (r.status_code >= 400): + raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {r.reason}") + if __name__ == '__main__': - module = Tracker_Term() module.run() diff --git a/requirements.txt b/requirements.txt index 8dde88c7..cb38df0b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -77,6 +77,7 @@ PySocks>=1.7.1 pycountry>=20.7.3 https://github.com/saffsd/langid.py/archive/master.zip +requests ##### Old packages