import Exceptions import base64, datetime import tomlkit, sqlite3 # kw == 'k'ey 'w'ord; dt_now = date&&time in UTC # Please consider adding more salt to prevent uid duplication(specially under multi-user use case) 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) # ----- Methods binding command to model ----- # Toml def getTomlDoc(tomlName): try: with open(tomlName, "rb") as t: doc = tomlkit.load(t) if doc == {}: Exceptions.err0() return doc except: Exceptions.err0() 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 == '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: rl.append(d[table][key]) return rl # Sqlite3 def operate_sqlite3(dbPath, command): con = sqlite3.connect(dbPath) cur = con.cursor() # cur.execute() cur.close() # Markdown # csv # MongoDB # ----- Transit Command Handler ----- def transitHandler(transit_command): dbType = transit_command[-1] dbPath = transit_command[-2] exec_command = transit_command[0:-3] if dbType == "sqlite3": operate_sqlite3(dbPath, exec_command) if dbType == "csv": pass if dbType == "mongodb": pass if dbType == "toml": pass if dbType == "md": pass else: input("err 1: correct db not found") exit()