Integrate changes

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-18 21:02:13 +01:00
commit 8a2c09696a
3 changed files with 22 additions and 12 deletions

View file

@ -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))

View file

@ -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)

View file

@ -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