Skip to content

Instantly share code, notes, and snippets.

@ahmedlahrizi
Created July 8, 2021 12:02
Show Gist options
  • Save ahmedlahrizi/560593fc78456b4e604fd1fe1ee6f85e to your computer and use it in GitHub Desktop.
Save ahmedlahrizi/560593fc78456b4e604fd1fe1ee6f85e to your computer and use it in GitHub Desktop.
if max_nb_chars < 25:
# join words
while not text:
size = 0
# determine how many words are needed to reach the $max_nb_chars
# once;
while size < max_nb_chars:
word = (self.word_connector if size else '') + \
self.word(ext_word_list=ext_word_list)
text.append(word)
size += len(word)
text.pop()
text[0] = text[0][0].upper() + text[0][1:]
last_index = len(text) - 1
text[last_index] += self.sentence_punctuation
elif max_nb_chars < 100:
# join sentences
while not text:
size = 0
# determine how many sentences are needed to reach the
# $max_nb_chars once
while size < max_nb_chars:
sentence = (self.word_connector if size else '') + \
self.sentence(ext_word_list=ext_word_list)
text.append(sentence)
size += len(sentence)
text.pop()
else:
# join paragraphs
while not text:
size = 0
# determine how many paragraphs are needed to reach the
# $max_nb_chars once
while size < max_nb_chars:
paragraph = ('\n' if size else '') + \
self.paragraph(ext_word_list=ext_word_list)
text.append(paragraph)
size += len(paragraph)
text.pop()
return "".join(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment