twitools/lyricsbot.py
2017-01-27 23:25:00 +01:00

24 lines
899 B
Python
Executable file

#!/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))