示例#1
0
    def update(self, event, vk, spl):
        if len(spl) < 3:
            send_message(event, vk, message=self.full_help)
            return

        if len(spl) > 3:
            ScheduleData.homework[ScheduleData.get_lesson_number(spl[2])] = event.text.replace("/homework ", "", 1)\
                .replace(spl[1], "", 1).replace(spl[2], "", 1)
            send_message(event, vk, message="Добавил")
            return

        if len(spl) == 3:
            if "reply_message" in event.message_data and "text" in event.message_data["reply_message"]\
                    and event.message_data["reply_message"]["text"] != "":
                ScheduleData.homework[ScheduleData.get_lesson_number(spl[2])] \
                    = event.message_data["reply_message"]["text"]
                send_message(event, vk, message="Добавил")
            elif "fwd_messages" in event.message_data and len(event.message_data["fwd_messages"]) != 0 \
                    and "text" in event.message_data["fwd_messages"][0] \
                    and event.message_data["fwd_messages"][0]["text"] != "":
                ScheduleData.homework[ScheduleData.get_lesson_number(spl[2])] \
                    = event.message_data["fwd_messages"][0]["text"]
                send_message(event, vk, message="Добавил")
            else:
                send_message(event, vk, message=self.full_help)
示例#2
0
    def update(self, event, vk, spl):
        if len(spl) < 6:
            send_message(event, vk, message=self.full_help)
            return

        ScheduleData.week.days[ScheduleData.get_day_number(
            spl[2])].lessons[int(spl[3]) - 1] = Lesson(
                ScheduleData.get_lesson_number(spl[5]), spl[4],
                len(spl) > 6 and spl[6] == "лекция")

        send_message(event, vk, message="Сделал")
示例#3
0
    def delete(self, event, vk, spl):
        if len(spl) < 3:
            send_message(event, vk, message=self.full_help)
            return

        ScheduleData.homework[ScheduleData.get_lesson_number(spl[2])] = None
        send_message(event, vk, message="Не хочется делать, да?")
示例#4
0
    def update(self, event, vk, spl):
        if len(spl) < 3:
            send_message(event, vk, message=self.full_help)
            return

        if len(spl) == 4:
            ScheduleData.homework[ScheduleData.get_lesson_number(
                spl[2])] = event.text.replace("/homework ", "", 1).replace(
                    spl[1], "", 1).replace(spl[2], "", 1)
            send_message(event, vk, message="Добавил")

        if len(spl) == 3:
            if len(event.message_data["reply_message"]["text"]) > 0:
                ScheduleData.homework[ScheduleData.get_lesson_number(
                    spl[2])] = event.message_data["reply_message"]["text"]
                send_message(event, vk, message="Добавил")
示例#5
0
    def delete(self, event, vk, spl):
        if len(spl) < 4:
            send_message(event, vk, message=self.full_help)
            return

        ScheduleData.week.days[ScheduleData.get_day_number(
            spl[2])].lessons[int(spl[3]) - 1] = Lesson(-1, None, None)

        send_message(event, vk, message="Удалил, а зря!")
示例#6
0
    def show_day(event, vk, spl):
        day_name = spl[2]
        message = f"Расписание на {day_name}\n"
        is_found = False
        for i, lesson in enumerate(ScheduleData.week.days[
                ScheduleData.get_day_number(day_name)].lessons):
            if lesson.lesson_id != -1:
                message += f"Пара: {i + 1}, аудитория: {lesson.classroom}, предмет: " \
                    f"{list_of_lesson_names[lesson.lesson_id][0]}, {'не ' if not lesson.is_lecture else ''}лекция\n"
                is_found = True

        if is_found:
            send_message(event, vk, message=message)
示例#7
0
    def reset(self, event, vk, spl):
        if len(spl) < 3:
            send_message(event, vk, message=self.full_help)
            return

        target_day = ScheduleData.get_day_number(spl[2])
        iso = datetime.today().isocalendar()
        is_even_week = (
            iso[1] -
            1) % 2 == 0 if target_day < iso[2] - 1 else iso[1] % 2 == 0

        ScheduleData.week.days[target_day] = default_days_even[target_day] \
            if is_even_week else default_days_odd[target_day]

        send_message(event, vk, message="Сбросил")
示例#8
0
    def show_day(event, vk, day_name):
        message = f"Дз на {day_name}\n"
        is_found = False
        for lesson in ScheduleData.week.days[ScheduleData.get_day_number(
                day_name)].lessons:
            if lesson.lesson_id == -1:
                continue

            homework = ScheduleData.homework[lesson.lesson_id]
            if homework is not None and not lesson.is_lecture:
                is_found = True
                message += f"{list_of_lesson_names[lesson.lesson_id][0]}: {homework}\n"
        send_message(event,
                     vk,
                     message=message
                     if is_found else f"Ничего на {day_name} нет, радуйтесь!")
示例#9
0
    def show(self, event, vk, spl):
        if len(spl) < 3:
            send_message(event, vk, message=self.full_help)
            return

        try:
            homework = ScheduleData.homework[ScheduleData.get_lesson_number(
                spl[2])]
            send_message(
                event,
                vk,
                message=
                f"Дз по {list_of_lesson_names[ScheduleData.get_lesson_number(spl[2])][0]}: {homework}"
                if homework is not None else "Ничего нет, радуйтесь!")
        except StopIteration:
            self.show_day(event, vk, spl[2])
示例#10
0
    def show(self, event, vk, spl):
        if len(spl) == 3:
            self.show_day(event, vk, spl)
            return

        if len(spl) < 4:
            send_message(event, vk, message=self.full_help)
            return

        lesson = ScheduleData.week.days[ScheduleData.get_day_number(
            spl[2])].lessons[int(spl[3]) - 1]

        if lesson.lesson_id == -1:
            send_message(event, vk, message="В это время ничего нет.")
            return

        send_message(
            event,
            vk,
            message=f"Я нашел!\nАудитория: {lesson.classroom}, предмет: "
            f"{list_of_lesson_names[lesson.lesson_id][0]}, {'не ' if not lesson.is_lecture else ''}лекция"
        )
示例#11
0
    def run(self):
        while True:
            sleep(60 * 10)

            with open("save_schedule/schedule", "wb") as f:
                f.write(ScheduleData.dump())