From 064543f4150a805cc620ca3994b0aae7a49f9ab8 Mon Sep 17 00:00:00 2001 From: Dmitry <124861781+ada-dmitry@users.noreply.github.com> Date: Thu, 27 Nov 2025 15:17:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20Dockerfile=20=D0=B8=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=81=20Trilium=20=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B7=20Telegram=20=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 15 +++++++++++++++ main.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dockerfile create mode 100644 main.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b400ac2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11-slim + +ENV PYTHONUNBUFFERED=1 + +# Устанавливаем системные зависимости +RUN apt-get update && apt-get install -y --no-install-recommends \ + libmagic1 file \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY main.py . +RUN pip install --no-cache-dir trilium-py dotenv aiogram + +CMD ["python", "main.py"] diff --git a/main.py b/main.py new file mode 100644 index 0000000..86cf83a --- /dev/null +++ b/main.py @@ -0,0 +1,53 @@ +import os +from dotenv import load_dotenv +from aiogram import Bot, Dispatcher +from aiogram.client.default import DefaultBotProperties +from aiogram.enums import ParseMode +from aiogram.filters import CommandStart +from aiogram.types import Message +from trilium_py.client import ETAPI + +load_dotenv() + +TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN") +TRILIUM_URL = os.getenv("TRILIUM_URL") +TRILIUM_TOKEN = os.getenv("TRILIUM_TOKEN") +INBOX_NOTE_ID = os.getenv("INBOX_NOTE_ID") + +# создаем Trilium API клиент +ea = ETAPI(server_url=TRILIUM_URL, token=TRILIUM_TOKEN) + +bot = Bot(token=TELEGRAM_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) + +dp = Dispatcher() + + +@dp.message(CommandStart()) +async def start(msg: Message): + await msg.answer("Отправь мне текст — я создам заметку в Trilium.") + + +@dp.message() +async def handler(msg: Message): + text = msg.text.strip() + + # разделяем на заголовок и тело + lines = text.split("\n", 1) + title = lines[0][:100] # заголовок = первая строка + content = lines[1] if len(lines) > 1 else "" # остальное — тело заметки + + ea.create_note( + parentNoteId=INBOX_NOTE_ID, title=title, content=content, type="text" + ) + + await msg.answer("Заметка сохранена в Trilium.") + + +async def main(): + await dp.start_polling(bot) + + +if __name__ == "__main__": + import asyncio + + asyncio.run(main())