Example #1
0
def set_options():
    # this whole function seems ugly and it looks like there's
    # a better way to do this but I still need to come up with it
    global DEFAULTS, CONFIG, STEP, CALC_RATIOS
    cfg_handler = JSONHandler(CONFIG)
    print("\nAvailable settings:")
    option = input("Step - decides what range is used to display entries - can be (1), (7) or (31) days > ")
    if option == '1':
        STEP = 86400 # 24 hours
    elif option == '7':
        STEP = 604800 # a week
    elif option == '31':
        STEP = 2678400 # a month

    option = input("Ratios - decides what ratios are used for savings calculator, input in form of 3 integers that sum up to 1.0 > ")
    option = option.split()
    if len(option) == 3:
        helper_list = []
        for opt in option:
            helper_list.append(float(opt))
        CALC_RATIOS = helper_list

    cfg_handler.clear(prompt = False)
    DEFAULTS = [["step", STEP], ["calc_ratios", CALC_RATIOS]] # especially this part is ugly
    cfg_handler.dump(DEFAULTS)
    print("Settings saved.")
Example #2
0
def read_config():
    global STEP, CALC_RATIOS, DEFAULTS, CONFIG
    cfg_handler = JSONHandler(CONFIG)
    cfg_contents = cfg_handler.load()
    
    if cfg_contents == None:
        cfg_handler.dump(DEFAULTS)
    else:
        for level in cfg_contents:
            for option in level:
                if option[0] == "step":
                    STEP = option[1]
                elif option[0] == "calc_ratios":
                    CALC_RATIOS = option[1]