Use replies in Markov bot, removing starting/ending handles
This commit is contained in:
parent
8a2c09696a
commit
04758ed796
14
markov.py
14
markov.py
|
@ -13,10 +13,20 @@ class Possy(markovify.NewlineText):
|
||||||
sentence = " ".join(word.split("::")[0] for word in words)
|
sentence = " ".join(word.split("::")[0] for word in words)
|
||||||
return sentence
|
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()):
|
def getText(db = dbtools.dbHelper()):
|
||||||
text = ""
|
text = ""
|
||||||
for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "@%" AND text NOT LIKE "RT %";'):
|
for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "RT %";'):
|
||||||
text += string[0] + "\n"
|
text += sanitizeText(string[0]) + "\n"
|
||||||
return html.unescape("".join([s for s in text.strip().splitlines(True) if s.strip()]))
|
return html.unescape("".join([s for s in text.strip().splitlines(True) if s.strip()]))
|
||||||
|
|
||||||
def markovifyText(text):
|
def markovifyText(text):
|
||||||
|
|
Loading…
Reference in a new issue