Use replies in Markov bot, removing starting/ending handles

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-18 22:14:35 +01:00
parent 8a2c09696a
commit 04758ed796

View file

@ -13,10 +13,20 @@ class Possy(markovify.NewlineText):
sentence = " ".join(word.split("::")[0] for word in words)
return sentence
def sanitizeText(text):
try:
if text[0] == "@":
return sanitizeText(text.partition(" ")[2])
if text.split()[-1][0] == "@":
return sanitizeText(" ".join(text.split()[:-1]))
except:
return ""
return text
def getText(db = dbtools.dbHelper()):
text = ""
for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "@%" AND text NOT LIKE "RT %";'):
text += string[0] + "\n"
for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "RT %";'):
text += sanitizeText(string[0]) + "\n"
return html.unescape("".join([s for s in text.strip().splitlines(True) if s.strip()]))
def markovifyText(text):