<commit_before>import json
import os


class DataStore(object):
    def __init__(self, storagePath="desertbot_data.json"):
        self.storagePath = storagePath
        self.data = None
        self.load()

    def load(self):
        if not os.path.exists(self.storagePath):
            self.data = {}
            self.save()
            return
        with open(self.storagePath) as storageFile:
            self.data = json.load(storageFile)

    def save(self):
        tmpFile = "{}.tmp".format(self.storagePath)
        with open(tmpFile, "w") as storageFile:
            storageFile.write(json.dumps(self.data, indent=4))
        os.rename(tmpFile, self.storagePath)<commit_msg>Allow using DataStore class as if dict<commit_after>import json
import os


class DataStore(object):
    def __init__(self, storagePath="desertbot_data.json"):
        self.storagePath = storagePath
        self.data = {}
        self.load()

    def load(self):
        if not os.path.exists(self.storagePath):
            self.save()
            return
        with open(self.storagePath) as storageFile:
            self.data = json.load(storageFile)

    def save(self):
        tmpFile = "{}.tmp".format(self.storagePath)
        with open(tmpFile, "w") as storageFile:
            storageFile.write(json.dumps(self.data, indent=4))
        os.rename(tmpFile, self.storagePath)

    def __len__(self):
        return len(self.data)

    def __iter__(self):
        return iter(self.data)

    def __getitem__(self, item):
        return self.data[item]
{'fraction_non_alphanumeric': 0.11341542449773169, 'fraction_numerical': 0.0012961762799740765, 'mean_word_length': 2.37117903930131, 'pattern_counts': {'":': 0, '<': 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': '199190', 'n_tokens_mistral': 462, 'n_tokens_neox': 455, 'n_words': 98}