Skip to content

Commit

Permalink
Adjusted the filter to the new structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirblc committed Nov 2, 2020
1 parent 60cc8fe commit 204610c
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 204610c

Please sign in to comment.