Добавлена вспомогательная функция _children для упрощения обработки дочерних элементов и улучшена логика поиска папок и заметок в функции save_daily
All checks were successful
Deploy bot / build-deploy (push) Successful in 28s
All checks were successful
Deploy bot / build-deploy (push) Successful in 28s
This commit is contained in:
15
main.py
15
main.py
@@ -45,6 +45,12 @@ def _get_content(obj):
|
|||||||
return obj.get("content") if isinstance(obj, dict) else getattr(obj, "content", "")
|
return obj.get("content") if isinstance(obj, dict) else getattr(obj, "content", "")
|
||||||
|
|
||||||
|
|
||||||
|
def _children(obj):
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
return obj.get("children") or []
|
||||||
|
return getattr(obj, "children", []) or []
|
||||||
|
|
||||||
|
|
||||||
def _translate_month_en_ru(name: str) -> str:
|
def _translate_month_en_ru(name: str) -> str:
|
||||||
mapping = {
|
mapping = {
|
||||||
"January": "Январь",
|
"January": "Январь",
|
||||||
@@ -101,8 +107,7 @@ def save_daily(text: str) -> str:
|
|||||||
|
|
||||||
# Ищем/создаём месяц
|
# Ищем/создаём месяц
|
||||||
month_folder = None
|
month_folder = None
|
||||||
if hasattr(daily_root, "children"):
|
for child in _children(daily_root):
|
||||||
for child in daily_root.children:
|
|
||||||
if _get_title(child) == month_name:
|
if _get_title(child) == month_name:
|
||||||
month_folder = child
|
month_folder = child
|
||||||
break
|
break
|
||||||
@@ -117,8 +122,7 @@ def save_daily(text: str) -> str:
|
|||||||
|
|
||||||
# Ищем/создаём день
|
# Ищем/создаём день
|
||||||
day_folder = None
|
day_folder = None
|
||||||
if hasattr(month_folder, "children"):
|
for child in _children(month_folder):
|
||||||
for child in month_folder.children:
|
|
||||||
if _get_title(child) == day_name:
|
if _get_title(child) == day_name:
|
||||||
day_folder = child
|
day_folder = child
|
||||||
break
|
break
|
||||||
@@ -131,8 +135,7 @@ def save_daily(text: str) -> str:
|
|||||||
|
|
||||||
# Ищем заметку по дате
|
# Ищем заметку по дате
|
||||||
existing_note = None
|
existing_note = None
|
||||||
if hasattr(day_folder, "children"):
|
for child in _children(day_folder):
|
||||||
for child in day_folder.children:
|
|
||||||
if _get_title(child) == today_date:
|
if _get_title(child) == today_date:
|
||||||
existing_note = child
|
existing_note = child
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user