123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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 <Code>: unexpected error in existence check")
- class command():
- pass
- class objBoard():
- pass
- class objClass():
- pass
- class objEvent():
- pass
|