From 8b16e698c835fa06de33c3796fa303cc8713bac9 Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 11 Sep 2019 15:43:18 +1000 Subject: [PATCH] handle case where there's no posts to learn from --- functions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/functions.py b/functions.py index 56115f9..5c599ee 100644 --- a/functions.py +++ b/functions.py @@ -95,19 +95,22 @@ def make_post(args): # 3. convert the tuple to a list # 4. join the list into a string separated by newlines posts = "\n".join(list(sum(c.fetchall(), ()))) + if len(posts) == 0: + print("No posts to learn from.") + return model = nlt_fixed(posts) tries = 0 post = None - # even with such a high tries value for markovify, it still sometimes returns none. - # so we implement our own tries function as well, and try ten times. if bot['fake_mentions'] == 'never': # remove all mentions from the training data before the markov model sees it posts = re.sub(r"@(\w+)@([\w.]+)\s?", "", posts) + # even with such a high tries value for markovify, it still sometimes returns none. + # so we implement our own tries function as well, and try ten times. while post is None and tries < 10: - post = model.make_short_sentence(bot['length'], tries = 10000) + post = model.make_short_sentence(bot['length'], tries = 1000) tries += 1 if post == None: