Merge branch 'master' of git.klaus-uwe.me:kumitterer/twitools
This commit is contained in:
commit
2a56054f52
3 changed files with 41 additions and 7 deletions
|
@ -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))
|
||||
|
|
30
lyricsmanager.py
Executable file
30
lyricsmanager.py
Executable file
|
@ -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()
|
16
markov.py
16
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()]))
|
||||
|
||||
|
|
Loading…
Reference in a new issue