Integrate changes
This commit is contained in:
commit
a36a11886f
3 changed files with 22 additions and 12 deletions
|
@ -24,9 +24,6 @@ def postprocess(lid, tid, db = dbtools.dbHelper()):
|
||||||
db.executeQuery("UPDATE lyrics SET active = 1 WHERE ref = %i;" % int(lid))
|
db.executeQuery("UPDATE lyrics SET active = 1 WHERE ref = %i;" % int(lid))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def tweet(text, ref = 0, two = twitools.twoHelper(setuptools.LYRICS)):
|
|
||||||
return two.tweet(text, ref).id
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
lid, text, ref = getLyrics()
|
lid, text, ref = getLyrics()
|
||||||
postprocess(lid, tweet(text, ref))
|
postprocess(lid, twitools.tweet(text, ref, setuptools.LYRICS))
|
||||||
|
|
26
markov.py
26
markov.py
|
@ -1,16 +1,26 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import dbtools, setuptools, twitools
|
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()):
|
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):
|
def markovifyText(text):
|
||||||
return markovify.Text(text).make_short_sentence(130).replace("@", "@")
|
return Possy(text).make_short_sentence(130).replace("@", "@")
|
||||||
|
|
||||||
def tweet(text, ref = 0, two = twitools.twoHelper(setuptools.MARKOV)):
|
|
||||||
return two.tweet(text, ref).id
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tweet(markovify(getText()))
|
twitools.tweet(markovifyText(getText()), section = setuptools.MARKOV)
|
||||||
|
|
|
@ -47,3 +47,6 @@ def twoHelper(section = setuptools.TWITTER):
|
||||||
return twObject(ato = setuptools.ato(section), ase = setuptools.ase(section))
|
return twObject(ato = setuptools.ato(section), ase = setuptools.ase(section))
|
||||||
except:
|
except:
|
||||||
return twObject()
|
return twObject()
|
||||||
|
|
||||||
|
def tweet(text, ref = 0, section = setuptools.TWITTER):
|
||||||
|
return twoHelper(section).tweet(text, ref).id
|
||||||
|
|
Loading…
Reference in a new issue