import sqlite3, time, socket class CalDB: __DBVERSION__="1" def __init__(self, dbPath): self.path=dbPath self.con=sqlite3.connect(dbPath) self.cur=self.con.cursor() # Init database res=self.cur.execute('SELECT name FROM sqlite_master WHERE type="table" AND name="infos";') if res.fetchone() is None: self.initDB() def initDB(self): # Infos table self.cur.execute("CREATE TABLE infos(name UNIQUE, value TEXT)") self.cur.execute('INSERT INTO infos VALUES("dbversion", "'+CalDB.__DBVERSION__+'")') self.cur.execute('INSERT INTO infos VALUES("creation", "'+str(time.time())+'")') self.cur.execute('INSERT INTO infos VALUES("created_on", "'+socket.gethostname()+'")') # Calendars table self.cur.execute("CREATE TABLE calendars(id INTEGER PRIMARY KEY, name TEXT, description TEXT, color TEXT, type INTEGER)") # Events table self.cur.execute("CREATE TABLE events(id INTEGER PRIMARY KEY, name TEXT, calendar INTEGER, description TEXT, start REAL, end REAL, repeat INTEGER, frequency INTEGER, location INTEGER, FOREIGN KEY(calendar) REFERENCES calendars(id))") self.con.commit() def keyExists(self, db, key): res=self.cur.execute("SELECT * FROM {} WHERE id={}".format(db,key)) return not res.fetchone() is None def addEvent(self, event): """ Event format: { name: str, calendar: int, desc: str, start: float, end: float, repeat: str, frequency: int } """ pass