2023-04-30 22:13:02 +00:00
|
|
|
|
2023-05-01 00:46:08 +00:00
|
|
|
import os
|
2023-04-30 22:13:02 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2023-04-30 22:18:25 +00:00
|
|
|
import contentapi
|
2023-05-01 00:46:08 +00:00
|
|
|
import toml
|
|
|
|
|
|
|
|
CONFIGFILE="config.toml"
|
2023-04-30 22:13:02 +00:00
|
|
|
|
|
|
|
# The entire config object with all defaults
|
|
|
|
config = {
|
2023-04-30 22:49:30 +00:00
|
|
|
"api" : "https://oboy.smilebasicsource.com/api",
|
|
|
|
"tokenfile" : ".qcstoken"
|
2023-04-30 22:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def main():
|
|
|
|
print("Program start")
|
2023-05-01 00:46:08 +00:00
|
|
|
load_or_create_global_config()
|
2023-04-30 22:13:02 +00:00
|
|
|
logging.debug("Config: " + json.dumps(config, indent = 2))
|
2023-04-30 22:57:50 +00:00
|
|
|
context = contentapi.ApiContext(config["api"], logging)
|
2023-04-30 22:18:25 +00:00
|
|
|
print("Program end")
|
|
|
|
|
2023-05-01 00:46:08 +00:00
|
|
|
# Loads the config from file into the global config var. If the file
|
|
|
|
# doesn't exist, the file is created from the defaults in config.
|
|
|
|
# The function returns nothing
|
|
|
|
def load_or_create_global_config():
|
|
|
|
global config
|
|
|
|
# Check if the config file exists
|
|
|
|
if os.path.exists(CONFIGFILE):
|
|
|
|
# Read and deserialize the config file
|
|
|
|
with open(CONFIGFILE, 'r', encoding='utf-8') as f:
|
|
|
|
config = toml.load(f)
|
|
|
|
else:
|
|
|
|
# Serialize and write the config dictionary to the config file
|
|
|
|
logging.warn("No config found at " + CONFIGFILE + ", creating now")
|
|
|
|
with open(CONFIGFILE, 'w', encoding='utf-8') as f:
|
|
|
|
toml.dump(config, f)
|
|
|
|
|
|
|
|
|
2023-04-30 22:18:25 +00:00
|
|
|
# Because python reasons
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|