123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import Alt
- import base64, datetime
- import tomlkit, sqlite3
- def generate_uid(kw):
- dt_now = str(datetime.datetime.now(datetime.timezone.utc))
- genText = str.encode(kw + "_" + dt_now)
- uid = base64.b64encode(genText)
-
- return(uid)
- 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])
- def MatchTomlKeys(tomlName, keys, table=None) -> list:
- doc = GetTomlDoc(tomlName)
- if table == None:
-
- 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
- def Operate_sqlite3(dbPath, match_commands):
- matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, "sqlite3")
- s = "".join(matchedSyntax).format(tableName = match_commands[2])
-
- con = sqlite3.connect(dbPath)
- cur = con.cursor()
-
- res = cur.execute(s)
- res.fetchone()
-
- con.close()
- def PackHandler(app_commands):
- dbType = app_commands[-1]
- dbPath = app_commands[-2]
- if dbType == "sqlite3":
- Operate_sqlite3(dbPath, app_commands)
- elif dbType == "csv":
- pass
- elif dbType == "mongodb":
- pass
- elif dbType == "toml":
- pass
- elif dbType == "md":
- pass
- else:
- input("error 1: could not found correct Data Base")
- exit()
- if __name__ == "__main__":
- a_c = ['/', 'test.db', 'sqlite3']
- a_c1 = ['add', 'board', 'testBoardName', 'test.db', 'sqlite3']
- a_c2 = ['edit', 'board', 't_boardName', 'to', 't_newBoardName', 'test.db', 'sqlite3']
- e_c = ['add', 'board']
-
- PackHandler(a_c2)
-
|