Apparently actually got a working lyricsbot...
This commit is contained in:
parent
9534e104f5
commit
ff0dfb4dc4
24
lyricsbot.py
Executable file
24
lyricsbot.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import dbtools, twitools
|
||||
import argparse, operator, random, re, sys
|
||||
|
||||
def getLyrics(db = dbtools.dbHelper()):
|
||||
lyrics = db.executeQuery("SELECT id, text, ref FROM lyrics WHERE active = 1")
|
||||
lyric = random.sample(list(lyrics), 1)[0]
|
||||
ref = list(db.executeQuery("SELECT tweet_id FROM lyrics WHERE id = %s" % lyric[2]))[0][0] if not int(lyric[2]) == 0 else 0
|
||||
|
||||
return lyric[0], lyric[1], ref
|
||||
|
||||
def postprocess(lid, tid, db = dbtools.dbHelper()):
|
||||
db.executeQuery("UPDATE lyrics SET tweet_id = %i WHERE id = %i;" % (int(tid), int(lid)))
|
||||
db.executeQuery("UPDATE lyrics SET active = 1 WHERE ref = %i;" % int(lid))
|
||||
db.executeQuery("UPDATE lyrics SET active = 0 WHERE id = %i;" % int(lid))
|
||||
db.commit()
|
||||
|
||||
def tweet(text, ref = 0, two = twitools.twObject()):
|
||||
return two.tweet(text, ref).id
|
||||
|
||||
if __name__ == "__main__":
|
||||
lid, text, ref = getLyrics()
|
||||
postprocess(lid, tweet(text, ref))
|
Loading…
Reference in a new issue