forked from kjhayes/wildhacks-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcript.py
29 lines (24 loc) · 811 Bytes
/
transcript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import threading
class Transcript():
def __init__(self, window_size, full=''):
self.full = full
self.window_size = window_size
self.mut = threading.Lock()
def get_window_bytes(self) -> bytes:
self.mut.acquire()
raw = self.full.encode()
raw = raw[len(raw)-self.window_size:len(raw)]
# Trim the first potentially mangled sentence
i = min(raw.find(b'.'), raw.find(b'\n'), -1)
self.mut.release()
return raw[i+1:]
def get_full(self):
# This might be sync overkill but better safe than sorry
self.mut.acquire()
full = self.full
self.mut.release()
return full
def append(self, addition: str):
self.mut.acquire()
self.full += addition
self.mut.release()