import Alt import tomlkit, sqlite3 # uid related # ----- Toml Methods ----- def GetTomlDoc(tomlName): try: with open(tomlName, "rb") as t: doc = tomlkit.load(t) if doc == {}: input("error 0: could not found correct config file") exit() return doc except: input("error 0: could not found correct config file") exit() def MatchTomlKey(tomlName, key, table=None) -> str: doc = GetTomlDoc(tomlName) if table == None: return str(doc.item(key)) elif table != None: d = doc.unwrap() return str(d[table][key]) # no differernt between ↑ MatchTomlKey() ↑ except receives and returns in list def MatchTomlKeys(tomlName, keys, table=None) -> list: doc = GetTomlDoc(tomlName) if table == None: # rl == 'r'eturn 'l'ist rl = [] for key in keys: try: rl.append(doc.item(key)) except: pass return rl elif table != None: rl = [] d = doc.unwrap() for key in keys: try: rl.append(d[table][key]) except: pass return rl # ----- Sqlite ----- def Exec_one(dbPath, commands): con = sqlite3.connect(dbPath) cur = con.cursor() cur.execute(commands) con.commit() re = cur.fetchall() con.close() return re def IsExist(exec_commands, returnBool=True): tableName = str(exec_commands[1]).capitalize() ItemName = str(exec_commands[2]) sqls = "SELECT name FROM {table} WHERE name='{name}'".format(table=tableName, name=ItemName) ie = Exec_one(dbPath, sqls) if ie != [] and returnBool == False: return ie elif ie != [] and returnBool == True: return True elif ie == []: return False else: # Alt.Err(errCode) print("err : unexpected error in existence check") class command(): pass class objBoard(): pass class objClass(): pass class objEvent(): pass