diff --git a/lyricsbot.py b/lyricsbot.py index e467e26..afe1e01 100755 --- a/lyricsbot.py +++ b/lyricsbot.py @@ -26,4 +26,4 @@ def postprocess(lid, tid, db = dbtools.dbHelper()): if __name__ == "__main__": lid, text, ref = getLyrics() - postprocess(lid, twitools.tweet(text, ref, setuptools.LYRICS)) + postprocess(lid, twitools.tweet("%s (#%i)" % (text, int(lid)), ref, setuptools.LYRICS)) diff --git a/lyricsmanager.py b/lyricsmanager.py new file mode 100755 index 0000000..82d6fb4 --- /dev/null +++ b/lyricsmanager.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import dbtools + +def addLyrics(text, ref = 0, db = dbtools.dbHelper()): + db.executeQuery("INSERT INTO lyrics(text, ref, active) VALUES('%s', %i, %i);" % (text, ref, (1 if ref == 0 else 0))) + db.commit() + return db.cur.lastrowid + +def queryLyrics(ref = 0): + text = input("Text: ") + + if len(text) > 130: + print("Text too long (%i characters)" % len(text)) + return queryLyrics(ref) + + ref = int(input("Reference [%i]: " % ref) or ref) + + row = addLyrics(text, ref) + + ans = "" + + while ans.lower() not in ("y", "n"): + ans = input("Add follow-up lyrics? [Y/n] ") + + if ans.lower() != "n": + queryLyrics(row) + +if __name__ == "__main__": + queryLyrics() diff --git a/markov.py b/markov.py index 0eeb2ff..d220e3b 100755 --- a/markov.py +++ b/markov.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import dbtools, setuptools, twitools -import argparse, html, markovify, nltk, operator, random, re, sys +import argparse, html, markovify, nltk, operator, random, re, string, sys class Possy(markovify.NewlineText): def word_split(self, sentence): @@ -14,18 +14,22 @@ class Possy(markovify.NewlineText): return sentence def sanitizeText(text): + split = text.split() try: - if text[0] == "@": - return sanitizeText(text.partition(" ")[2]) - if text.split()[-1][0] == "@": - return sanitizeText(" ".join(text.split()[:-1])) + if "@" in (text[0], text[1]): + if split[1][0] not in string.ascii_lowercase: + return sanitizeText(text.partition(" ")[2]) + if split[-1][0] == "@": + return sanitizeText(" ".join(split[:-1])) + if text[:4] == "RT @": + return sanitizeText(text.partition(":")[2]) except: return "" return text def getText(db = dbtools.dbHelper()): text = "" - for string in db.executeQuery('SELECT text FROM tweets WHERE text NOT LIKE "RT %";'): + for string in db.executeQuery('SELECT text FROM tweets;'): text += sanitizeText(string[0]) + "\n" return html.unescape("".join([s for s in text.strip().splitlines(True) if s.strip()]))