diff --git a/dict_dl.py b/dict_dl.py index da1672ec..af92e418 100644 --- a/dict_dl.py +++ b/dict_dl.py @@ -1,4 +1,5 @@ import json +import os import random import re import string @@ -163,8 +164,11 @@ class FileSet(set): class DictFile(dict): def __init__(self, file): self.file = file - with open(self.file, "r") as f: - super().__init__(json.load(f)) + if os.path.isfile(self.file): + with open(self.file, "r") as f: + super().__init__(json.load(f)) + else: + super() def save(self): with open(self.file, "w") as f: @@ -191,7 +195,7 @@ class Queue: suffix, time_base=1.01, time_exponent=10, - prefix_length=1, + prefix_length=3, ): self.__dict__.update(locals()) self.words = set() @@ -205,9 +209,9 @@ class Queue: time.sleep(randtime(a, b)) def loadDB(self): - for db_file in Path(self.dir_prefix).glob(f"*{self.suffix}"): - with open(db_file, "r") as f: - self.words |= set(json.load(f).keys()) + d = FullDictionary(self.dir_prefix, self.suffix) + self.words |= set(d.keys()) + print(d.readtime) def add_word(self): self.redo.load() @@ -268,5 +272,6 @@ class Queue: if __name__ == "__main__": f = FileSet("en_merriam_webster/queue") - d = DictFile("en_merriam_webster/ab_mw.json") + # d = DictFile("en_merriam_webster/abc_mw.json") + # d.save() print(d)