diff --git a/main.py b/main.py
index fdfe3b9..f5cbc85 100644
--- a/main.py
+++ b/main.py
@@ -82,10 +82,19 @@ def relevant_filter_func(d: dict) -> bool:
return False
return True
-def deadlines_filter_func(d: dict) -> bool:
+def tests_filter_func(d: dict) -> bool:
if "[тест]" in d["name"].lower():
- return False
- return True
+ return True
+ return False
+
+def deadline_type_filter_func(d: dict, dtype: str) -> bool:
+ if f"[{dtype.lower()}]" in d["name"].lower():
+ return True
+ return False
+
+def deadlines_filter_func(d: dict) -> bool:
+ return (not deadline_type_filter_func(d, "тест") and
+ not deadline_type_filter_func(d, "лекция"))
async def get_message_text() -> str:
try:
@@ -93,14 +102,17 @@ async def get_message_text() -> str:
except Exception as e:
print(f"{datetime.datetime.now()} Failed to fetch deadlines: {e}")
return ""
- deadlines = response["deadlines"]
+ all_deadlines = response["deadlines"]
- tests = list(filter(lambda t: not deadlines_filter_func(t) and relevant_filter_func(t), deadlines))
- deadlines = list(filter(lambda d: deadlines_filter_func(d) and relevant_filter_func(d), deadlines))
+ deadlines = list(filter(lambda d: deadlines_filter_func(d) and relevant_filter_func(d), all_deadlines))
+ tests = list(filter(lambda t: deadline_type_filter_func(t, "тест") and relevant_filter_func(t), all_deadlines))
+ lectures = list(filter(lambda t: deadline_type_filter_func(t, "лекция") and relevant_filter_func(t), all_deadlines))
text = f"🔥️️ Дедлайны (Обновлено в {await get_current_time()} 🔄):\n\n"
- tests = sorted(tests, key=lambda x: timestamp_func(x))
+
deadlines = sorted(deadlines, key=lambda x: timestamp_func(x))
+ tests = sorted(tests, key=lambda x: timestamp_func(x))
+ lectures = sorted(lectures, key=lambda x: timestamp_func(x))
if len(deadlines) == 0:
text += "Дедлайнов нет)\n\n"
@@ -146,12 +158,38 @@ async def get_message_text() -> str:
text += f"\n("
text += await get_human_time(tests[i]["time"]) + ")\n\n"
+ if len(lectures) > 0:
+ text += f"\n👨🏫 Лекции:\n\n"
+
+ for i in range(len(lectures)):
+ lecture_name = lectures[i]["name"].replace("[Лекция] ", "").replace("[лекция]", "")
+ lecture_url = lectures[i].get("url")
+ no = i + 1
+ if no < 11:
+ no = NUMBER_EMOJIS[no] + " "
+ else:
+ no += ". "
+ text += str(no) + ""
+
+ if lecture_url:
+ text += f"{lecture_name}"
+ else:
+ text += lecture_name
+
+ text += " — "
+ text += await get_human_timedelta(lectures[i]["time"])
+ text += f"\n("
+ text += await get_human_time(lectures[i]["time"]) + ")\n\n"
+
text += f"\n🆕 " \
- f"Добавить дедлайн/тест"
+ f"Добавить дедлайн"
return text
async def send_deadlines(chat_id: int) -> None:
text = await get_message_text()
+ if text == "Дедлайнов нет)\n\n":
+ return
+
msg = await bot.send_message(chat_id, text, parse_mode="HTML", disable_web_page_preview=True)
started_updating = dt.datetime.now()
print(datetime.datetime.now(), "Message sent. Msg id:", msg.message_id)