Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testCheckModels(self):
for m in self.tm.models.values():
self.assertIsInstance(m, markovify.text.NewlineText)
#!/usr/bin/env python3
import markovify.text
helptext = "Outputs a markov chain from /r/conspiracy comments"
logfile = "../conspiradump.txt" #This is only here for testing and debugging.
with open(logfile) as f:
text = f.read()
model = markovify.text.NewlineText(text, state_size=3)
async def doit(irc, target, source, sentences=2):
#Maybe we'll replace this with a server-side thing on donger.org that provides a
#response in the form of something like "donger.org/conspiracy.php?sentences=2".
#That would make it so we don't have to put a 1MB text file in a repo.
#
#We could call it "Conspiracies As A Service"
longstring = ''
for i in range(sentences):
try:
sentence = model.make_sentence(tries=20).strip()
if sentence.endswith("." or "?"):
longstring += "{} ".format(sentence)
def make_title(song):
while True:
title_generator = markovify.text.NewlineText(song)
title = title_generator.make_sentence()
if title is not None:
title_list = title.split(" ")
title = " ".join(title_list[0:3])
return title.title()
try:
for pth in corpora:
if isinstance(pth, six.string_types):
corpus_path = os.path.expanduser(pth)
name = os.path.basename(corpus_path)
m = open(corpus_path)
else:
m = pth
try:
name = m.name
except AttributeError:
name = repr(m)
try:
out[name] = markovify.text.NewlineText(m.read(), state_size=state_size)
finally:
m.close()
except AttributeError as e:
self.log.error(e)
self.log.error("Probably couldn't find the model file.")
raise e
except IOError as e:
self.log.error(e)
self.log.error('Error reading %s', corpus_path)
raise e
self.default_model = os.path.basename(corpora[0])