feat: add /select_choice route
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append('..')
|
||||
#sys.path.append('..')
|
||||
from mongo_worker import MongoWorker
|
||||
from schemas.base_schemas import Card
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import re
|
||||
|
||||
from tools.data.dirty_words import dirty_words_set
|
||||
|
||||
def is_not_empty(text: str) -> bool:
|
||||
"""Checks that the text is not empty."""
|
||||
return bool(text.strip())
|
||||
|
||||
def has_no_links(text: str) -> bool:
|
||||
"""Checks that there are no links in the text."""
|
||||
url_pattern = re.compile(r'https?://\S+|www\.\S+')
|
||||
return not bool(url_pattern.search(text))
|
||||
|
||||
def has_no_dirty_words(text: str) -> bool:
|
||||
"""Checks that there are no forbidden words in the text."""
|
||||
words = set(re.findall(r'\w+', text.lower()))
|
||||
return not bool(words & dirty_words_set)
|
||||
|
||||
def text_lenght(text: str) -> bool:
|
||||
"""Check max text lenght"""
|
||||
return len(text) <= 150 # TODO: update in future
|
||||
|
||||
def moderate_text(text: str) -> bool:
|
||||
return is_not_empty(text) and has_no_links(text) and has_no_dirty_words(text) and text_lenght(text)
|
||||
@@ -31,8 +31,8 @@
|
||||
},
|
||||
{
|
||||
"card_id": 3,
|
||||
"choice_A": "Поездка в горы",
|
||||
"choice_B": "Поездка на море",
|
||||
"choice_A": "Отпуск в горах",
|
||||
"choice_B": "Отпуск на море",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user