2017-02-15 18:09:48 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import dbtools, twitools
|
2017-02-15 21:19:20 +00:00
|
|
|
|
import argparse, markovify, nltk, operator, random, re, sys
|
|
|
|
|
|
|
|
|
|
class Possy(markovify.NewlineText):
|
|
|
|
|
def word_split(self, sentence):
|
|
|
|
|
words = re.split(self.word_split_pattern, sentence)
|
|
|
|
|
words = [ "::".join(tag) for tag in nltk.pos_tag(words) ]
|
|
|
|
|
return words
|
|
|
|
|
|
|
|
|
|
def word_join(self, words):
|
|
|
|
|
sentence = " ".join(word.split("::")[0] for word in words)
|
|
|
|
|
return sentence
|
2017-02-15 18:09:48 +00:00
|
|
|
|
|
|
|
|
|
def getText(db = dbtools.dbHelper()):
|
2017-02-15 18:16:19 +00:00
|
|
|
|
text = ""
|
|
|
|
|
for string in db.executeQuery("SELECT text FROM tweets;"):
|
|
|
|
|
text += string[0] + "\n"
|
2017-02-15 21:19:20 +00:00
|
|
|
|
return "".join([s for s in text.strip().splitlines(True) if s.strip()])
|
2017-02-15 18:09:48 +00:00
|
|
|
|
|
2017-02-15 18:16:19 +00:00
|
|
|
|
def markovifyText(text):
|
2017-02-15 21:19:20 +00:00
|
|
|
|
return Possy(text).make_short_sentence(130).replace("@", "@")
|
2017-02-15 18:09:48 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-02-15 21:42:38 +00:00
|
|
|
|
twitools.tweet(markovifyText(getText()))
|