Добавлена вспомогательная функция для получения ID заметок и улучшена обработка папок для ежедневных заметок
All checks were successful
Deploy bot / build-deploy (push) Successful in 26s
All checks were successful
Deploy bot / build-deploy (push) Successful in 26s
This commit is contained in:
53
main.py
53
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():
|
||||
|
||||
Reference in New Issue
Block a user