add first course

This commit is contained in:
kr0sh512
2024-09-03 00:40:08 +03:00
parent 3c0be433ae
commit 28b2640327
4 changed files with 100 additions and 72 deletions
+29 -49
View File
@@ -58,50 +58,20 @@ def change_user_param(id, key, value):
with open(path_users, "w", encoding="utf-8") as json_file:
json.dump(data, json_file, ensure_ascii=False, indent=4)
create_schedule_tasks()
bot.send_admin_message(
"Изменения:\
\n<i>user:</i> @{}\
\n<i>id:</i> <code>{}</code>\
\n<i>key:</i> <code>{}</code>\
\n<i>value:</i> <code>{}</code>".format(
data[id]["username"], id, key, value
)
)
# bot.send_admin_message(
# "Изменения:\
# \n<i>user:</i> @{}\
# \n<i>id:</i> <code>{}</code>\
# \n<i>key:</i> <code>{}</code>\
# \n<i>value:</i> <code>{}</code>".format(
# data[id]["username"], id, key, value
# )
# )
return
def parse_lesson_tmp(time, lesson):
text = ""
start, end = time.split("-")
if len(lesson["infos"].split("|")) == 2:
teacher = lesson["infos"].split("|")[0]
room = lesson["infos"].split("|")[1]
text = "{}-{} | {}\
\n<b>{}</b>\
\n<i>{}</i>".format(
start, end, room, lesson["name"], teacher
)
elif len(lesson["infos"].split("|")) == 4:
infos = lesson["infos"].split("|")
text = "{}-{}\
\n<b>{}</b>\
\n({}) <i>{}</i>\
\n({}) <i>{}</i>".format(
start, end, lesson["name"], infos[1], infos[0], infos[3], infos[2]
)
elif len(lesson["infos"].split("|")) == 1:
text = "{}-{}\
\n<b>{}</b>".format(
start, end, lesson["name"]
)
else:
print("что-то не так")
print(lesson["name"])
return text
def parse_lesson(lesson: dict[str, str]) -> str:
text = ""
start, end = lesson["begin"], lesson["end"]
@@ -128,6 +98,8 @@ def parse_lesson(lesson: dict[str, str]) -> str:
)
for tr in lesson["teacher.room"]:
if not tr["t"] and not tr["r"]:
continue
text += "\n({}) <i>{}</i>".format(tr["r"], tr["t"])
return text
@@ -140,7 +112,7 @@ def create_schedule_tasks(manual=False):
if not allow_update:
return
bot.send_admin_message("Произошёл auto-update")
# bot.send_admin_message("Произошёл auto-update")
allow_update = True
@@ -184,27 +156,27 @@ def create_schedule_tasks(manual=False):
if day == "mon":
schedule.every().monday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "tue":
schedule.every().tuesday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "wed":
schedule.every().wednesday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "thu":
schedule.every().thursday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "fri":
schedule.every().friday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
elif day == "sat":
schedule.every().saturday.at(start_task).do(
bot.send_message, id, text, thread_id, lesson["partity"]
bot.send_message, id, text, thread_id, lesson["parity"]
)
return
@@ -311,8 +283,16 @@ def get_schedule(id: str, day: str) -> str:
)
for lesson in schdl_today:
text += "" + parse_lesson(lesson) + "\n\n"
str_lesson = parse_lesson(lesson)
if str_lesson:
text += "" + str_lesson + "\n\n"
except:
return "Расписания твоей группы нет"
return text
if __name__ == "__main__":
print(groups_in_json())
pass