separate picking from add_word

This commit is contained in:
juvilius 2022-07-11 08:10:43 +02:00
parent c91ba9f320
commit e96b1e8199
Signed by untrusted user who does not match committer: julius
GPG Key ID: 3EAC91A848E1D685

View File

@ -207,6 +207,7 @@ class Queue:
self.unusual = lambda prefix: not all([c in letters for c in prefix.lower()]) or len(prefix) < self.prefix_length
def wait(self):
self.time_exponent = abs(self.time_exponent)
a = self.time_base**self.time_exponent
b = self.time_base ** (self.time_exponent * 3)
time.sleep(randtime(a, b))
@ -216,13 +217,23 @@ class Queue:
with open(db_file, "r") as f:
self.words |= set(json.load(f).keys())
def add_word(self):
def pick_random(self):
self.redo.load()
self.queue -= self.words
self.queue -= self.snafus
self.queue |= self.redo
len_queue = len(self.queue) # actual queue
if len(self.queue) < 1:
p = random.choice(list(self.words))
self.time_exponent += 1
else:
p = random.choice(list(self.queue))
self.time_exponent -= 20
else:
return p
def add_word(self, p=None):
if p == None:
p = self.pick_random()
try:
start_parsing = time.time()
w = self.Parser(p) # fetch new word
@ -231,7 +242,7 @@ class Queue:
print(
f"{p} | "
f"{len(self.words)} words collected, "
f"{len_queue} words waiting in queue"
f"{len(self.queue)} words waiting in queue"
# f", {start_db_stuff-start_parsing:.06f}s"
# f"/{time.time() - start_db_stuff:.06f}s"
)