1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import tomlkit
- 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
|