import markovify import os import string import sys import shlex import unidecode combined_model = None text = "" dir = sys.argv[1] for (dirpath, _, filenames) in os.walk(dir): for filename in filenames: with open(os.path.join(dirpath, filename)) as f: text = text + unidecode.unidecode(f.read().lower()) # Build the model. text_model = markovify.NewlineText(text, well_formed = False) if len(sys.argv) > 1: insp = " ".join(map(shlex.quote, sys.argv[2:])).lower() print(text_model.make_sentence_with_start(unidecode.unidecode(insp), strict = False, tries = 1000)) else: print(text_model.make_short_sentence(280, tries=1000))