aboutsummaryrefslogtreecommitdiff
path: root/shared/samples.py
diff options
context:
space:
mode:
authorIgor Tolmachov <me@igorek.dev>2022-12-05 22:29:41 +0900
committerIgor Tolmachov <me@igorek.dev>2022-12-05 22:29:41 +0900
commit0de7969d30e3e57d681afdfcadd245f6988a0342 (patch)
treebc0957e9208f51354aa2330dc20a090b7f680823 /shared/samples.py
parent0d5cab62b0d077ad7946b64a534e3914f1cc79dd (diff)
downloadkarpov_ai_bot-0de7969d30e3e57d681afdfcadd245f6988a0342.tar.gz
karpov_ai_bot-0de7969d30e3e57d681afdfcadd245f6988a0342.zip
2.1
Diffstat (limited to 'shared/samples.py')
-rw-r--r--shared/samples.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/shared/samples.py b/shared/samples.py
new file mode 100644
index 0000000..740cff5
--- /dev/null
+++ b/shared/samples.py
@@ -0,0 +1,31 @@
1from tgen import TextGenerator
2
3from shared.database import Message
4from shared.instances import session
5
6
7class Samples:
8 samples: dict[int, TextGenerator]
9
10 def __init__(self) -> None:
11 self.samples = {}
12
13 def get(self, chat_id: int) -> TextGenerator:
14 if chat_id not in self.samples:
15 with session() as s:
16 samples = [
17 m.tuple()[0]
18 for m in s.query(Message.message)
19 .filter(Message.chat_id == chat_id)
20 .all()
21 ]
22
23 self.samples[chat_id] = TextGenerator.from_samples(samples)
24 return self.samples[chat_id]
25
26 def delete(self, chat_id: int) -> None:
27 if chat_id in self.samples:
28 self.samples.pop(chat_id)
29
30
31samples = Samples()