code: def generate(topic, add_punctuation, character_count=None):
      
      corpus_cursor = db.markovify.find({'topic': topic})
      if(corpus_cursor):
          corpus = ''
          for text in corpus_cursor:
              corpus = punctuate(corpus, text['text'], add_punctuation)
          text_model = markovify.Text(corpus)
          sentence = text_model.make_short_sentence(character_count) \
              if character_count else text_model.make_sentence()
          if not sentence:
              raise Exception('There is not enough in the corpus to generate a sentence.')
          return sentence
      raise Exception('No text found for topic: ' + topic)
docs: Generate the text for a given topic