From 204610c45ad7aba02c332ec0869321147aed30f9 Mon Sep 17 00:00:00 2001 From: Shir Bar Lev Date: Mon, 2 Nov 2020 21:41:19 +0000 Subject: [PATCH] Adjusted the filter to the new structure. --- filter.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/filter.py b/filter.py index 6f751d56..ffbb56ea 100644 --- a/filter.py +++ b/filter.py @@ -25,34 +25,21 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from wordfilter import Wordfilter +from models import Filter -# Filter class, which extends Wordfilter +# Filter class +# inspired by Wordfilter: https://pypi.org/project/wordfilter/ class Filter(Wordfilter): - # Gets the list of blacklisted words, excluding the words - # built into the module - def get_words(self): - return self.blacklist[66:len(self.blacklist)] - - # Gets the full list of blacklisted words - # Only to be used by the backend! - def get_full_list(self): - return self.blacklist - - # Remove a word from the list - def remove_word(self, index): - remove_index = int(index) + 65 - return self.blacklist.pop(remove_index) - # Check if there's a blacklisted word in the text def blacklisted(self, string): + filtered_words = Filter.query.all() test_string = string.lower() badword_indexes = [] is_blacklisted = False; # Check each word - for badword in self.blacklist: - if(badword in test_string): + for filter in filtered_words: + if(filter.filter in test_string): is_blacklisted = True; badword_indexes.append({ 'badword': badword,