feat: creating FastAPI routes for working with cards
Added 3 routes: - add_card (add a card via POST request with AddCardBody scheme) - get_card (get a specific card by card_id) - get_random_cards (get 10 random cards)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import re
|
||||
|
||||
from 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 moderate_text(text: str) -> bool:
|
||||
return is_not_empty(text) and has_no_links(text) and has_no_dirty_words(text)
|
||||
Reference in New Issue
Block a user