diff --git a/db_connection.py b/db_connection.py new file mode 100755 index 0000000..4eae65c --- /dev/null +++ b/db_connection.py @@ -0,0 +1,60 @@ +#!/usr/bin/python3 +import sqlite3 +import logging as log + +database = "bbbbs.sqlite" +log.basicConfig(level=log.INFO, encoding="utf-8") # set level to log.DEBUG when debugging + +try: + sqliteConnection = sqlite3.connect(database) + cursor = sqliteConnection.cursor() + + cursor.execute('select sqlite_version();') + log.debug("Sqlite version is %s" % cursor.fetchall()) + log.info("connected to %s" % database) +except sqlite3.Error as error: + log.critical('Error occured: ', error) + + +def create_transmissions_table(): + # timeslots is stored as a 10 bit number with each bit representing a specific timeslot. + scheme = """ + CREATE TABLE IF NOT EXISTS transmissions ( + date TEXT NOT NULL, + author TEXT NOT NULL, + title TEXT NOT NULL, + tranmission_text TEXT NOT NULL, + timeslots INT NOT NULL, + transmission_order INT NOT NULL, + play BOOLEAN NOT NULL + ); + """ + if cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='transmissions';").fetchall() == []: + try: + cursor.execute(scheme) + log.info("Successfully created database transmissions") + except sqlite3.Error as error: + log.critical("Couldn't create transmissions table: ", error) + exit(1) + else: + log.debug('DB transmissions exists, not creating.') + +def create_timeslots_table(): + scheme = """ + CREATE TABLE IF NOT EXISTS timeslots ( + timeslot INT NOT NULL, + time TEXT NOT NULL, + active BOOLEAN NOT NULL + ); + """ + if cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='timeslots';").fetchall() == []: + try: + cursor.execute(scheme) + log.info("Successfully created database transmissions") + except sqlite3.Error as error: + log.critical("Couldn't create timeslots table: ", error) + exit(1) + +create_transmissions_table() +create_timeslots_table() +sqliteConnection.close() diff --git a/main.py b/main.py index 0f8ae1a..97dab3c 100755 --- a/main.py +++ b/main.py @@ -81,7 +81,6 @@ class MainWindow(Gtk.Window): self.timeslots = Gtk.ListBox() for slot in ["09:00", "15:00", "21:00"]: - print(slot) row = Gtk.ListBoxRow() hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50) row.add(hbox)