<commit_before>import json
import os
from util import user_dir

class SimpleConfig:
  default_options = {"gui": "lite"}

  def set_key(self, key, value, save = True):
    self.config[key] = value
    if save == True:
      self.save_config()

  def save_config(self):
    f = open(self.config_file_path(), "w+")
    f.write(json.dumps(self.config))

  def load_config(self):
    f = open(self.config_file_path(), "r")
    file_contents = f.read()
    if file_contents:
      self.config = json.loads(file_contents)
    else:
      self.config = self.default_options
      self.save_config()
  
  def config_file_path(self):
    return "%s" % (self.config_folder + "/config.json")

  def __init__(self):
    # Find electrum data folder
    self.config_folder = user_dir()
    # Read the file
    if os.path.exists(self.config_file_path()):
      self.load_config()
    else:
      self.config = self.default_options
      self.save_config()
        <commit_msg>reformat simple_config to comply with electrum and create config dir if it doesnt exist.<commit_after>import json
import os
from util import user_dir

class SimpleConfig:

    default_options = {"gui": "lite"}
    
    def __init__(self):
        # Find electrum data folder
        self.config_folder = user_dir()
        # Read the file
        if os.path.exists(self.config_file_path()):
            self.load_config()
        else:
            self.config = self.default_options
            # Make config directory if it does not yet exist.
            if not os.path.exists(self.config_folder):
                os.mkdir(self.config_folder)
            self.save_config()
        
    def set_key(self, key, value, save = True):
        self.config[key] = value
        if save == True:
            self.save_config()
    
    def save_config(self):
        f = open(self.config_file_path(), "w+")
        f.write(json.dumps(self.config))
    
    def load_config(self):
        f = open(self.config_file_path(), "r")
        file_contents = f.read()
        if file_contents:
            self.config = json.loads(file_contents)
        else:
            self.config = self.default_options
            self.save_config()
    
    def config_file_path(self):
        return "%s" % (self.config_folder + "/config.json")

{'fraction_non_alphanumeric': 0.11086765994741454, 'fraction_numerical': 0.0, 'mean_word_length': 2.4074626865671642, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3668976', 'n_tokens_mistral': 714, 'n_tokens_neox': 705, 'n_words': 166}