reload trx list on adding - currently broken
This commit is contained in:
40
db.py
40
db.py
@ -19,13 +19,14 @@ except sqlite3.Error as error:
|
||||
def create_transmissions_table():
|
||||
scheme = """
|
||||
CREATE TABLE IF NOT EXISTS transmissions (
|
||||
date TEXT NOT NULL,
|
||||
author TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
transmission_text TEXT NOT NULL,
|
||||
timeslots TEXT NOT NULL,
|
||||
transmission_order INT NOT NULL,
|
||||
play BOOLEAN NOT NULL
|
||||
uid TEXT NOT NULL UNIQUE,
|
||||
date TEXT,
|
||||
author TEXT,
|
||||
title TEXT,
|
||||
transmission_text TEXT,
|
||||
timeslots TEXT,
|
||||
transmission_order INT,
|
||||
play BOOLEAN
|
||||
);
|
||||
"""
|
||||
if cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='transmissions';").fetchall() == []:
|
||||
@ -33,7 +34,8 @@ def create_transmissions_table():
|
||||
cursor.execute(scheme)
|
||||
log.info("Successfully created database transmissions")
|
||||
except sqlite3.Error as error:
|
||||
log.critical("Couldn't create transmissions table: ", error)
|
||||
log.critical("Couldn't create transmissions table")
|
||||
log.critical(error)
|
||||
exit(1)
|
||||
else:
|
||||
log.debug('DB transmissions exists, not creating.')
|
||||
@ -41,16 +43,24 @@ def create_transmissions_table():
|
||||
def get_transmissions(date=None, timeslot=None):
|
||||
return cursor.execute("SELECT * FROM transmissions").fetchall()
|
||||
|
||||
def create_transmission(date, author, title, transmission_text, timeslots, transmission_order, play=True):
|
||||
command="""
|
||||
INSERT INTO transmissions VALUES(?, ?, ?, ?, ?, %d, %d);
|
||||
"""%(transmission_order, (1 if play else 0))
|
||||
def add_transmission(uid):
|
||||
command="INSERT INTO transmissions(uid, play) VALUES(?, 0)"
|
||||
try:
|
||||
cursor.execute(command, (date, author, title, transmission_text, timeslots))
|
||||
cursor.execute(command, (uid,))
|
||||
sqliteConnection.commit()
|
||||
log.debug("Created a transmission with date %s, author %s, timeslots %s"%(date, author, timeslots))
|
||||
log.debug("Created a transmission uid %s"%(uid))
|
||||
except sqlite3.Error as error:
|
||||
log.error("Couldn't create a transmission with date %s, author %s, timeslots %s"%(date, author, bin(timeslots)))
|
||||
log.error("Couldn't create a transmission with uid: %s"%(uid))
|
||||
log.error(error)
|
||||
|
||||
def edit_transmission(uid, date, author, title, transmission_text, timeslots, transmission_order, play):
|
||||
command="UPDATE transmissions set date=?, author=?, title=?, transmission_text=?, timeslots=?, transmission_order=?, play=? WHERE uid=?"
|
||||
try:
|
||||
cursor.execute(command, date, author, title, transmission_text, timeslots, transmission_order, play, uid)
|
||||
sqliteConnection.commit()
|
||||
log.debug("Updated a transmission with uid %s (date %s, author %s)"%(uid, date, author))
|
||||
except sqlite3.Error as error:
|
||||
log.error("Couldn't create a transmission with uid %s (date %s, author %s)"%uid, (date, author))
|
||||
log.error(error)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user