diff --git a/lyricsbot.py b/lyricsbot.py index 598170f..e467e26 100755 --- a/lyricsbot.py +++ b/lyricsbot.py @@ -24,9 +24,6 @@ def postprocess(lid, tid, db = dbtools.dbHelper()): db.executeQuery("UPDATE lyrics SET active = 1 WHERE ref = %i;" % int(lid)) db.commit() -def tweet(text, ref = 0, two = twitools.twoHelper(setuptools.LYRICS)): - return two.tweet(text, ref).id - if __name__ == "__main__": lid, text, ref = getLyrics() - postprocess(lid, tweet(text, ref)) + postprocess(lid, twitools.tweet(text, ref, setuptools.LYRICS)) diff --git a/markov.py b/markov.py index 64211fb..5aa5601 100755 --- a/markov.py +++ b/markov.py @@ -1,16 +1,26 @@ #!/usr/bin/env python3 import dbtools, setuptools, twitools -import argparse, markovify, operator, random, re, sys +import argparse, html, 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 def getText(db = dbtools.dbHelper()): - return '\n'.join(db.executeQuery("SELECT text FROM tweets;")) + text = "" + for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "@%" AND text NOT LIKE "RT %";'): + text += string[0] + "\n" + return html.unescape("".join([s for s in text.strip().splitlines(True) if s.strip()])) -def markovify(text): - return markovify.Text(text).make_short_sentence(130).replace("@", "@​") - -def tweet(text, ref = 0, two = twitools.twoHelper(setuptools.MARKOV)): - return two.tweet(text, ref).id +def markovifyText(text): + return Possy(text).make_short_sentence(130).replace("@", "@​") if __name__ == "__main__": - tweet(markovify(getText())) + twitools.tweet(markovifyText(getText()), section = setuptools.MARKOV) diff --git a/twitools/__init__.py b/twitools/__init__.py index 2e5dc80..e0439b3 100644 --- a/twitools/__init__.py +++ b/twitools/__init__.py @@ -47,3 +47,6 @@ def twoHelper(section = setuptools.TWITTER): return twObject(ato = setuptools.ato(section), ase = setuptools.ase(section)) except: return twObject() + +def tweet(text, ref = 0, section = setuptools.TWITTER): + return twoHelper(section).tweet(text, ref).id