twitools/lyricsmanager.py
2017-02-26 20:54:40 +01:00

45 lines
939 B
Python
Executable file

#!/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.replace("'", "''"), ref, (1 if ref == 0 else 0)))
db.commit()
return db.cur.lastrowid
def queryLyrics(ref = 0):
text = "."
out = ""
while text != "":
text = input("Text: ")
if out != "":
out += "\n%s" % text
else:
out = text
if len(out) == 0:
print("No input. Aborting.")
return False
elif len(out) > 130:
print("Text too long (%i characters)" % len(out))
return queryLyrics(ref)
ref = int(input("Reference [%i]: " % ref) or ref)
row = addLyrics(out, ref)
ans = "."
while ans.lower() not in ("y", "n", ""):
ans = input("Added as %i. Add follow-up lyrics? [Y/n] " % int(row))
if ans.lower() != "n":
return row
return False
if __name__ == "__main__":
row = 0
while row is not False:
row = queryLyrics(row)