From 4696d91af7e241da61d856c3b9f8794492ff4dbb Mon Sep 17 00:00:00 2001 From: kldk-lab Date: Sun, 19 Jan 2025 21:04:28 +0300 Subject: [PATCH 1/3] Delete main.py --- main.py | 74 --------------------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index 6fbb539..0000000 --- a/main.py +++ /dev/null @@ -1,74 +0,0 @@ -from textual.app import App, ComposeResult -from textual.widgets import Placeholder, Label, Static, Rule -from textual.containers import Horizontal, VerticalScroll, Vertical - -class T_m(): - """Класс объекта тестового сообщения (Test_message)""" - - def __init__(self, text: str, user: int): - """ - text - текст сообщения \n - user - айди отправителя сообщения - """ - - self.text = text - self.user = user - -class T_u(): - """Класс объекта тестового пользователя(Test_user)""" - - def __init__(self, name: str, user_id: int, dialog: list[T_m]): - """ - name - имя пользователя \n - id - айди пользователя \n - dialog - список сообщений (T_m) диалога - """ - - self.name = name - self.user_id = user_id - self.dialog = dialog - -client = T_u("вы", 0, []) - -test_chats = [T_u("антон", 1, [T_m("привет", 0), T_m("как дела?", 1), T_m("норм", 0)]), - T_u("лёха", 2, [T_m("как выйти из вима", 2), T_m("хелп", 2), T_m("никак", 0)]), - T_u("нифига", 3, [T_m("слушай, а как там лёха", 3), T_m("нифига", 0), T_m("нифигадлыроарыарышщращгшырашырвшщарш", 3)])] - -class Chat(Horizontal): - """Кастомный виджет чата слева""" - def __init__(self, user: T_u): - super().__init__() - self.user = user - - def _on_click(self): - pass - - def compose(self) -> ComposeResult: - with Horizontal(): - yield Label(f"┌───┐\n│ {self.user.name[:1]} │\n└───┘") - with Vertical(): - yield Label(self.user.name, id="name") - yield Label(self.user.dialog[-1].text) - -class TelegramTUI(App): - CSS_PATH = "styles.tcss" - - def compose(self) -> ComposeResult: - with Horizontal(): - with Horizontal(id="chats"): - with VerticalScroll(): - for i in test_chats: - yield Chat(i) - - yield Rule("vertical") - - with VerticalScroll(id="dialog"): - yield Placeholder(label="message", classes=("message")) - yield Placeholder(label="message", classes=("message")) - yield Placeholder(label="message", classes=("message")) - yield Placeholder(label="message", classes=("message")) - yield Placeholder(label="message", classes=("message")) - -if __name__ == "__main__": - app = TelegramTUI() - app.run() From fc422605c5e87715f9f4d1db6ab8e1e4c154ffc8 Mon Sep 17 00:00:00 2001 From: kldk-lab Date: Sun, 19 Jan 2025 21:06:16 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9E=D0=BD=D0=BE=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D1=83=D0=BC=D0=B5=D0=B5=D1=82=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D1=82=D1=8C=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Но нужно добавить async и await --- main.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tokens.py | 3 ++ 2 files changed, 100 insertions(+) create mode 100644 main.py create mode 100644 tokens.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..3114f56 --- /dev/null +++ b/main.py @@ -0,0 +1,97 @@ +from textual.app import App, ComposeResult +from textual.widgets import Placeholder, Label, Static, Rule +from textual.containers import Horizontal, VerticalScroll, Vertical +from telethon import TelegramClient, events, sync +from tokens import api_id, api_hash +import time + +names = [] +soo = [] + +limits = 6 + +client = TelegramClient('Telegram-Cli', api_id, api_hash) +client.start() +print(client.get_me().stringify()) + +for titles in client.iter_dialogs(limit=limits): + names.append('{:<14}'.format(titles.title)) +print(names) +time.sleep(3) + +for messages in client.iter_dialogs(limit=limits): + soo.append('{:<14}'.format(messages.message.message)) +print(soo) +time.sleep(3) + +class T_m(): + """Класс объекта тестового сообщения (Test_message)""" + + def __init__(self, text: str, user: int): + """ + text - текст сообщения \n + user - айди отправителя сообщения + """ + + self.text = text + self.user = user + +class T_u(): + """Класс объекта тестового пользователя(Test_user)""" + + def __init__(self, name: str, user_id: int, dialog: list[T_m]): + """ + name - имя пользователя \n + id - айди пользователя \n + dialog - список сообщений (T_m) диалога + """ + + self.name = name + self.user_id = user_id + self.dialog = dialog + +client = T_u("вы", 0, []) + +test_chats = [] + +for i in range(0, limits): + test_chats.append(T_u(names[i], 1, [T_m(soo[i], 0)])) + +class Chat(Horizontal): + """Кастомный виджет чата слева""" + def __init__(self, user: T_u): + super().__init__() + self.user = user + + def _on_click(self): + pass + + def compose(self) -> ComposeResult: + with Horizontal(): + yield Label(f"┌───┐\n│ {self.user.name[:1]} │\n└───┘") + with Vertical(): + yield Label(self.user.name, id="name") + yield Label(self.user.dialog[-1].text) + +class TelegramTUI(App): + CSS_PATH = "styles.tcss" + + def compose(self) -> ComposeResult: + with Horizontal(): + with Horizontal(id="chats"): + with VerticalScroll(): + for i in test_chats: + yield Chat(i) + + yield Rule("vertical") + + with VerticalScroll(id="dialog"): + yield Placeholder(label="message", classes=("message")) + yield Placeholder(label="message", classes=("message")) + yield Placeholder(label="message", classes=("message")) + yield Placeholder(label="message", classes=("message")) + yield Placeholder(label="message", classes=("message")) + +if __name__ == "__main__": + app = TelegramTUI() + app.run() diff --git a/tokens.py b/tokens.py new file mode 100644 index 0000000..575694f --- /dev/null +++ b/tokens.py @@ -0,0 +1,3 @@ +# Values from this files willn't work! Replace it with your's from my.telegram.org +api_id = 4327852 +api_hash = "yourhash" From 30b268d7e6118236ea28485c8023da3cf62c8fb4 Mon Sep 17 00:00:00 2001 From: kldk-lab Date: Sun, 19 Jan 2025 21:18:57 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B5=D0=B9=20=D1=85=D1=80=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Например time который я использовал для отладки и надписи о тестовых классах --- main.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/main.py b/main.py index 3114f56..03e3ca6 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ from textual.widgets import Placeholder, Label, Static, Rule from textual.containers import Horizontal, VerticalScroll, Vertical from telethon import TelegramClient, events, sync from tokens import api_id, api_hash -import time names = [] soo = [] @@ -16,16 +15,11 @@ print(client.get_me().stringify()) for titles in client.iter_dialogs(limit=limits): names.append('{:<14}'.format(titles.title)) -print(names) -time.sleep(3) for messages in client.iter_dialogs(limit=limits): soo.append('{:<14}'.format(messages.message.message)) -print(soo) -time.sleep(3) class T_m(): - """Класс объекта тестового сообщения (Test_message)""" def __init__(self, text: str, user: int): """ @@ -37,7 +31,6 @@ class T_m(): self.user = user class T_u(): - """Класс объекта тестового пользователя(Test_user)""" def __init__(self, name: str, user_id: int, dialog: list[T_m]): """