Добавлена вспомогательная функция для получения 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)
|
daily_root = ea.get_note(DAILY_NOTE_ID)
|
||||||
month_folder = None
|
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"):
|
if hasattr(daily_root, "children"):
|
||||||
for child in 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
|
month_folder = child
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -94,41 +103,59 @@ async def handler(msg: Message):
|
|||||||
parentNoteId=DAILY_NOTE_ID, title=month_name, type="text"
|
parentNoteId=DAILY_NOTE_ID, title=month_name, type="text"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
month_id = get_id(month_folder)
|
||||||
|
|
||||||
# Ищем папку дня внутри месячной папки
|
# Ищем папку дня внутри месячной папки
|
||||||
day_folder = None
|
day_folder = None
|
||||||
if hasattr(month_folder, "children"):
|
month_folder_refresh = ea.get_note(month_id)
|
||||||
for child in month_folder.children:
|
if hasattr(month_folder_refresh, "children"):
|
||||||
if day_name in child.title:
|
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
|
day_folder = child
|
||||||
break
|
break
|
||||||
|
|
||||||
if not day_folder:
|
if not day_folder:
|
||||||
# Создаём папку дня, если её нет
|
# Создаём папку дня, если её нет
|
||||||
day_folder = ea.create_note(
|
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
|
existing_note = None
|
||||||
if hasattr(day_folder, "children"):
|
day_folder_refresh = ea.get_note(day_id)
|
||||||
for child in day_folder.children:
|
if hasattr(day_folder_refresh, "children"):
|
||||||
if child.title == today_date:
|
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
|
existing_note = child
|
||||||
break
|
break
|
||||||
|
|
||||||
if existing_note:
|
if existing_note:
|
||||||
# Дописываем в существующую заметку
|
# Дописываем в существующую заметку
|
||||||
|
existing_content = (
|
||||||
|
existing_note.get("content")
|
||||||
|
if isinstance(existing_note, dict)
|
||||||
|
else existing_note.content
|
||||||
|
)
|
||||||
new_content = (
|
new_content = (
|
||||||
existing_note.content + "\n\n---\n" + content
|
existing_content + "\n\n---\n" + content
|
||||||
if existing_note.content
|
if existing_content
|
||||||
else 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}.")
|
await msg.answer(f"Добавлено в ежедневную заметку за {today_date}.")
|
||||||
else:
|
else:
|
||||||
# Создаём новую заметку на сегодня
|
# Создаём новую заметку на сегодня
|
||||||
ea.create_note(
|
ea.create_note(
|
||||||
parentNoteId=day_folder.noteId,
|
parentNoteId=day_id,
|
||||||
title=today_date,
|
title=today_date,
|
||||||
content=content,
|
content=content,
|
||||||
type="text",
|
type="text",
|
||||||
@@ -141,7 +168,7 @@ async def handler(msg: Message):
|
|||||||
ea.create_note(
|
ea.create_note(
|
||||||
parentNoteId=INBOX_NOTE_ID, title=title, content=content, type="text"
|
parentNoteId=INBOX_NOTE_ID, title=title, content=content, type="text"
|
||||||
)
|
)
|
||||||
await msg.answer("Заметка сохранена в Trilium. Сто пудов!")
|
await msg.answer("Заметка сохранена в Trilium.")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user