diff --git a/bin/RegexForTermsFrequency.py b/bin/RegexForTermsFrequency.py index b5570ea9..d1534eab 100755 --- a/bin/RegexForTermsFrequency.py +++ b/bin/RegexForTermsFrequency.py @@ -37,7 +37,7 @@ top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, to def refresh_dicos(): - dico_regex = {} + dico_regex = {} dico_regexname_to_redis = {} for regex_str in server_term.smembers(TrackedRegexSet_Name): dico_regex[regex_str[1:-1]] = re.compile(regex_str[1:-1]) @@ -90,18 +90,15 @@ if __name__ == "__main__": if matched is not None: #there is a match print('regex matched {}'.format(regex_str)) matched = matched.group(0) - + regex_str_complete = "/" + regex_str + "/" # Add in Regex track set only if term is not in the blacklist - if matched not in server_term.smembers(BlackListTermsSet_Name): - + if regex_str_complete not in server_term.smembers(BlackListTermsSet_Name): # Send a notification only when the member is in the set - if matched in server_term.smembers(TrackedTermsNotificationEnabled_Name): - + if regex_str_complete in server_term.smembers(TrackedTermsNotificationEnabled_Name): # Send to every associated email adress - for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + matched): - sendEmailNotification(email, matched) + for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + regex_str_complete): + sendEmailNotification(email, regex_str) - set_name = 'regex_' + dico_regexname_to_redis[regex_str] new_to_the_set = server_term.sadd(set_name, filename) new_to_the_set = True if new_to_the_set == 1 else False diff --git a/bin/SetForTermsFrequency.py b/bin/SetForTermsFrequency.py index d6e9bef9..014ce10e 100755 --- a/bin/SetForTermsFrequency.py +++ b/bin/SetForTermsFrequency.py @@ -75,7 +75,6 @@ if __name__ == "__main__": else: continue - message = p.get_from_set() while True: @@ -103,19 +102,17 @@ if __name__ == "__main__": for the_set, matchingNum in match_dico.items(): eff_percent = float(matchingNum) / float((len(ast.literal_eval(the_set))-1)) * 100 #-1 bc if the percent matching if eff_percent >= dico_percent[the_set]: - # Send a notification only when the member is in the set - if the_set in server_term.smembers(TrackedTermsNotificationEnabled_Name): - + if dico_setname_to_redis[str(the_set)] in server_term.smembers(TrackedTermsNotificationEnabled_Name): # Send to every associated email adress - for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + the_set): - sendEmailNotification(email, the_set) - + for email in server_term.smembers(TrackedTermsNotificationEmailsPrefix_Name + dico_setname_to_redis[str(the_set)]): + sendEmailNotification(email, dico_setname_to_redis[str(the_set)]) + print(the_set, "matched in", filename) set_name = 'set_' + dico_setname_to_redis[the_set] new_to_the_set = server_term.sadd(set_name, filename) new_to_the_set = True if new_to_the_set == 1 else False - + #consider the num of occurence of this set set_value = int(server_term.hincrby(timestamp, dico_setname_to_redis[the_set], int(1))) diff --git a/var/www/modules/terms/Flask_terms.py b/var/www/modules/terms/Flask_terms.py index 0811a4c0..015ba94f 100644 --- a/var/www/modules/terms/Flask_terms.py +++ b/var/www/modules/terms/Flask_terms.py @@ -330,18 +330,17 @@ def terms_management_action(): if re.match(r"[^@]+@[^@]+\.[^@]+", email): validNotificationEmails.append(email) - # add all valid emails to the set - for email in validNotificationEmails: - r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term.lower(), email) - - # enable notifications by default - r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower()) # check if regex/set or simple term #regex if term.startswith('/') and term.endswith('/'): r_serv_term.sadd(TrackedRegexSet_Name, term) r_serv_term.hset(TrackedRegexDate_Name, term, today_timestamp) + # add all valid emails to the set + for email in validNotificationEmails: + r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term, email) + # enable notifications by default + r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term) #set elif term.startswith('\\') and term.endswith('\\'): @@ -355,11 +354,21 @@ def terms_management_action(): set_to_add = "\\" + tab_term[:-1] + ", [{}]]\\".format(match_percent) r_serv_term.sadd(TrackedSetSet_Name, set_to_add) r_serv_term.hset(TrackedSetDate_Name, set_to_add, today_timestamp) + # add all valid emails to the set + for email in validNotificationEmails: + r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + set_to_add, email) + # enable notifications by default + r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, set_to_add) #simple term else: r_serv_term.sadd(TrackedTermsSet_Name, term.lower()) r_serv_term.hset(TrackedTermsDate_Name, term.lower(), today_timestamp) + # add all valid emails to the set + for email in validNotificationEmails: + r_serv_term.sadd(TrackedTermsNotificationEmailsPrefix_Name + term.lower(), email) + # enable notifications by default + r_serv_term.sadd(TrackedTermsNotificationEnabled_Name, term.lower()) elif action == "toggleEMailNotification": # get the current state diff --git a/var/www/modules/terms/templates/terms_management.html b/var/www/modules/terms/templates/terms_management.html index 778b5b76..41ac586f 100644 --- a/var/www/modules/terms/templates/terms_management.html +++ b/var/www/modules/terms/templates/terms_management.html @@ -129,7 +129,7 @@    

- {{ notificationEMailTermMapping[term] }} + {{ notificationEMailTermMapping[set] }} {% endfor %} @@ -146,7 +146,7 @@    

- {{ notificationEMailTermMapping[term] }} + {{ notificationEMailTermMapping[regex] }} {% endfor %} @@ -408,3 +408,6 @@ function perform_operation(){ } } + + +