From e4cafaefaf3a8f2275cec56a82494d96ebe89a06 Mon Sep 17 00:00:00 2001 From: Dmitry <124861781+ada-dmitry@users.noreply.github.com> Date: Fri, 12 Dec 2025 10:52:37 +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=D0=B0=20=D0=B2=D1=81=D0=BF=D0=BE=D0=BC=D0=BE=D0=B3=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20ID=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=BA=20=D0=B8=20=D1=83=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D0=BF=D0=B0=D0=BF=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B5=D0=B6=D0=B5=D0=B4=D0=BD=D0=B5=D0=B2?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index e43d997..6aa3807 100644 --- a/main.py +++ b/main.py @@ -81,10 +81,19 @@ async def handler(msg: Message): daily_root = ea.get_note(DAILY_NOTE_ID) month_folder = None + # Вспомогательная функция для получения ID + def get_id(obj): + if isinstance(obj, dict): + return obj.get("noteId") or obj.get("id") + return obj.noteId if hasattr(obj, "noteId") else obj.id + # Ищем папку месяца if hasattr(daily_root, "children"): for child in daily_root.children: - if month_name in child.title: + child_title = ( + child.get("title") if isinstance(child, dict) else child.title + ) + if month_name in child_title: month_folder = child break @@ -94,41 +103,59 @@ async def handler(msg: Message): parentNoteId=DAILY_NOTE_ID, title=month_name, type="text" ) + month_id = get_id(month_folder) + # Ищем папку дня внутри месячной папки day_folder = None - if hasattr(month_folder, "children"): - for child in month_folder.children: - if day_name in child.title: + month_folder_refresh = ea.get_note(month_id) + if hasattr(month_folder_refresh, "children"): + for child in month_folder_refresh.children: + child_title = ( + child.get("title") if isinstance(child, dict) else child.title + ) + if day_name in child_title: day_folder = child break if not day_folder: # Создаём папку дня, если её нет day_folder = ea.create_note( - parentNoteId=month_folder.noteId, title=day_name, type="text" + parentNoteId=month_id, title=day_name, type="text" ) + day_id = get_id(day_folder) + # Ищем заметку с сегодняшней датой existing_note = None - if hasattr(day_folder, "children"): - for child in day_folder.children: - if child.title == today_date: + day_folder_refresh = ea.get_note(day_id) + if hasattr(day_folder_refresh, "children"): + for child in day_folder_refresh.children: + child_title = ( + child.get("title") if isinstance(child, dict) else child.title + ) + if child_title == today_date: existing_note = child break if existing_note: # Дописываем в существующую заметку + existing_content = ( + existing_note.get("content") + if isinstance(existing_note, dict) + else existing_note.content + ) new_content = ( - existing_note.content + "\n\n---\n" + content - if existing_note.content + existing_content + "\n\n---\n" + content + if existing_content else content ) - ea.update_note(noteId=existing_note.noteId, content=new_content) + existing_id = get_id(existing_note) + ea.update_note(noteId=existing_id, content=new_content) await msg.answer(f"Добавлено в ежедневную заметку за {today_date}.") else: # Создаём новую заметку на сегодня ea.create_note( - parentNoteId=day_folder.noteId, + parentNoteId=day_id, title=today_date, content=content, type="text", @@ -141,7 +168,7 @@ async def handler(msg: Message): ea.create_note( parentNoteId=INBOX_NOTE_ID, title=title, content=content, type="text" ) - await msg.answer("Заметка сохранена в Trilium. Сто пудов!") + await msg.answer("Заметка сохранена в Trilium.") async def main():