Implemented #11

This commit is contained in:
REDNBLACK 2016-11-13 19:25:32 +03:00
parent eba9723780
commit e1a7f1c542
2 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import random
from src.config import config
from src.utils import *
from src.utils import strings_has_equal_letters, capitalize, random_element
from src.entity.word import Word
from src.entity.pair import Pair
@ -9,7 +10,12 @@ class ReplyGenerator:
pass
def generate(self, message):
return self.generate_story(message, message.words, random.randint(0, 2) + 1)
result = self.generate_story(message, message.words, random.randint(0, 2) + 1)
if strings_has_equal_letters(result, ''.join(message.words)):
return ''
return result
def generate_story(self, message, words, sentences_count):
word_ids = Word.where_in('word', words).lists('id').all()

View File

@ -1,10 +1,18 @@
import random
import re
def capitalize(string):
return string[:1].upper() + string[1:]
def strings_has_equal_letters(str1, str2):
def clear_symbols(string):
return re.sub(r'[\W_]', '', string).lower()
return clear_symbols(str1) == clear_symbols(str2)
def random_element(xlist):
return random.choice(xlist) if len(xlist) > 0 else None