示例#1
0
def select_master_id_handler(call_back):
    bot_msg = bot.edit_message_text(text="{0}\U00002026".format(
        choice(loading_text["schedule"])),
                                    chat_id=call_back.message.chat.id,
                                    message_id=call_back.message.message_id)
    answer = "{0} Расписание преподавателя: <b>{1}</b>\n\n{2} {3}"
    educator_schedule = spbu.get_educator_events(call_back.data)
    answer = answer.format(emoji["bust_in_silhouette"],
                           educator_schedule["EducatorLongDisplayText"],
                           emoji["calendar"],
                           educator_schedule["DateRangeDisplayText"])
    if not educator_schedule["HasEvents"]:
        answer += "\n\n<i>Нет событий</i>"
        bot.edit_message_text(text=answer,
                              chat_id=call_back.message.chat.id,
                              message_id=bot_msg.message_id,
                              parse_mode="HTML")
    else:
        bot.edit_message_text(text=answer,
                              chat_id=call_back.message.chat.id,
                              message_id=bot_msg.message_id,
                              parse_mode="HTML")
        days = [
            day for day in educator_schedule["EducatorEventsDays"]
            if day["DayStudyEventsCount"]
        ]
        for day in days:
            answer = func.create_master_schedule_answer(day)
            func.send_long_message(bot, answer, call_back.message.chat.id)
示例#2
0
def select_months_att_handler(call_back):
    bot_msg = bot.edit_message_text(
        text="{0}\U00002026".format(choice(loading_text["schedule"])),
        chat_id=call_back.message.chat.id,
        message_id=call_back.message.message_id
    )
    json_attestation = func.get_json_attestation(call_back.message.chat.id)
    answers = []
    is_full_place = func.is_full_place(call_back.message.chat.id)

    if call_back.message.text == "Выбери месяц:":
        schedule_variations = [(True, True, False), (False, True, False)]
    else:
        schedule_variations = [(True, False, True), (False, False, True)]

    for personal, session, only_resit in schedule_variations:
        answers = func.create_session_answers(json_attestation, call_back.data,
                                              call_back.message.chat.id,
                                              is_full_place, personal,
                                              session, only_resit)
        if answers:
            break
    if not answers:
        answers.append("<i>Нет событий</i>")
    try:
        bot.edit_message_text(text=answers[0],
                              chat_id=call_back.message.chat.id,
                              message_id=bot_msg.message_id,
                              parse_mode="HTML")
    except ApiException:
        func.send_long_message(bot, answers[0], call_back.message.chat.id)
    finally:
        for answer in answers[1:]:
            func.send_long_message(bot, answer, call_back.message.chat.id)
示例#3
0
文件: week.py 项目: oopoo196/spbu4u
def week_day_schedule_handler(call_back):
    bot_msg = bot.edit_message_text(text="{0}\U00002026".format(
        choice(loading_text["schedule"])),
                                    chat_id=call_back.message.chat.id,
                                    message_id=call_back.message.message_id)
    is_next_week = False
    iso_day_date = list((datetime.today() + server_timedelta).isocalendar())
    if iso_day_date[2] == 7:
        iso_day_date[1] += 1
    if call_back.data == "Следующее":
        iso_day_date[1] += 1
        is_next_week = True
    iso_day_date[2] = week_day_number[week_day_titles[
        call_back.message.text.split(": ")[-1]]]
    day_date = func.date_from_iso(iso_day_date)
    json_day = func.get_json_day_data(call_back.message.chat.id,
                                      day_date,
                                      next_week=is_next_week)
    full_place = func.is_full_place(call_back.message.chat.id)
    answer = func.create_schedule_answer(json_day, full_place,
                                         call_back.message.chat.id)
    try:
        bot.edit_message_text(text=answer,
                              chat_id=call_back.message.chat.id,
                              message_id=bot_msg.message_id,
                              parse_mode="HTML")
    except ApiException:
        func.send_long_message(bot, answer, call_back.message.chat.id)
示例#4
0
文件: days.py 项目: oopoo196/spbu4u
def schedule_for_interval(message):
    bot.send_chat_action(message.chat.id, "typing")
    from_date, to_date = func.text_to_interval(message.text.lower())
    json_data = func.get_json_interval_data(message.chat.id,
                                            from_date=from_date,
                                            to_date=to_date +
                                            timedelta(days=1))
    is_send = False
    full_place = func.is_full_place(message.chat.id)
    if len(json_data["Days"]) > 10:
        answer = "{0} Превышен интервал в <b>10 дней</b>".format(
            emoji["warning"])
        bot.send_message(text=answer,
                         chat_id=message.chat.id,
                         parse_mode="HTML")
        return
    elif len(json_data["Days"]):
        for day_info in json_data["Days"]:
            answer = func.create_schedule_answer(day_info, full_place,
                                                 message.chat.id)
            if "Выходной" in answer:
                continue
            func.send_long_message(bot, answer, message.chat.id)
            is_send = True

    if not is_send or not len(json_data["Days"]):
        answer = "{0} С <i>{1}</i> по <i>{2}</i> занятий нет".format(
            emoji["sleep"], func.datetime_to_string(from_date),
            func.datetime_to_string(to_date))
        bot.send_message(text=answer,
                         chat_id=message.chat.id,
                         parse_mode="HTML")
示例#5
0
文件: days.py 项目: oopoo196/spbu4u
def today_schedule_handler(message):
    bot.send_chat_action(message.chat.id, "typing")

    for_date = datetime.today().date() + server_timedelta
    if message.text.capitalize() == "Завтра":
        for_date += timedelta(days=1)

    json_day = func.get_json_day_data(message.chat.id, for_date)
    full_place = func.is_full_place(message.chat.id)
    answer = func.create_schedule_answer(json_day, full_place, message.chat.id)

    func.send_long_message(bot, answer, message.chat.id)
示例#6
0
文件: days.py 项目: oopoo196/spbu4u
def schedule_for_weekday(message):
    bot.send_chat_action(message.chat.id, "typing")
    message.text = message.text.title()
    if message.text in week_day_titles.values():
        week_day = message.text
    else:
        week_day = week_day_titles[message.text]

    day_date = func.get_day_date_by_weekday_title(week_day)
    json_day = func.get_json_day_data(message.chat.id, day_date)
    full_place = func.is_full_place(message.chat.id)
    answer = func.create_schedule_answer(json_day, full_place, message.chat.id)
    func.send_long_message(bot, answer, message.chat.id)
示例#7
0
文件: days.py 项目: oopoo196/spbu4u
def schedule_for_day(message):
    bot.send_chat_action(message.chat.id, "typing")
    day = func.text_to_date(message.text.lower())
    json_week = func.get_json_week_data(message.chat.id, for_day=day)
    json_day = func.get_json_day_data(message.chat.id,
                                      day_date=day,
                                      json_week_data=json_week)
    full_place = func.is_full_place(message.chat.id)
    answer = func.create_schedule_answer(json_day,
                                         full_place,
                                         user_id=message.chat.id,
                                         personal=True)
    func.send_long_message(bot, answer, message.chat.id)
示例#8
0
文件: days.py 项目: oopoo196/spbu4u
def now_lesson_handler(message):
    bot.send_chat_action(message.chat.id, "typing")

    today = datetime.today() + server_timedelta
    json_day = func.get_json_day_data(message.chat.id, today.date())
    full_place = func.is_full_place(message.chat.id)
    answer = func.create_schedule_answer(json_day, full_place, message.chat.id)

    if "Выходной" in answer:
        func.send_long_message(bot, answer, message.chat.id)
    else:
        lessons = answer.strip().split("\n\n")[1:]
        for lesson in lessons:
            times = []
            for st in lesson.split("\n")[0].split(" ")[-1].split(
                    emoji["en_dash"]):
                times.append(func.string_to_time(st))
            if times[0] <= today.time() <= times[1]:
                answer = "{0} <b>Пара:</b>\n{1}".format(emoji["books"], lesson)
                func.send_long_message(bot, answer, message.chat.id)
                return
            elif today.time() <= times[0] and today.time() <= times[1]:
                answer = "{0} <b>Перерыв</b>\n\nСледующая:\n{1}".format(
                    emoji["couch_and_lamp"], lesson)
                func.send_long_message(bot, answer, message.chat.id)
                return

    answer = "{0} Пары уже закончились".format(emoji["sleep"])
    func.send_long_message(bot, answer, message.chat.id)
示例#9
0
def schedule_sender():
    sql_con = get_connection()
    cursor = sql_con.cursor()
    cursor.execute("""SELECT id
                      FROM user_data
                      WHERE sending = 1""")
    data = cursor.fetchall()
    cursor.close()
    sql_con.close()

    send_cnt = 0
    err_cnt = 0

    tomorrow_moscow_datetime = \
        datetime.today() + timedelta(days=1) + server_timedelta
    tomorrow_moscow_date = tomorrow_moscow_datetime.date()

    for user_data in data:
        user_id = user_data[0]
        json_day = get_json_day_data(user_id, tomorrow_moscow_date)
        full_place = is_full_place(user_id)
        answer = create_schedule_answer(json_day, full_place, user_id)

        if "Выходной" in answer:
            continue

        try:
            answer = "Расписание на завтра:\n\n" + answer
            send_long_message(bot, answer, user_id)
            send_cnt += 1
        except Exception as err:
            print(err)
            print(user_id)
            err_cnt += 1
            continue

    return send_cnt, err_cnt
示例#10
0
文件: week.py 项目: oopoo196/spbu4u
def all_week_schedule_handler(call_back):
    user_id = call_back.message.chat.id
    bot_msg = bot.edit_message_text(text="{0}\U00002026".format(
        choice(loading_text["schedule"])),
                                    chat_id=call_back.message.chat.id,
                                    message_id=call_back.message.message_id)
    if call_back.data == "Текущее":
        json_week = func.get_json_week_data(user_id)
    else:
        json_week = func.get_json_week_data(user_id, next_week=True)
    inline_answer = json_week["WeekDisplayText"]
    bot.answer_callback_query(call_back.id, inline_answer, cache_time=1)
    is_send = False
    if len(json_week["Days"]):
        for day in json_week["Days"]:
            full_place = func.is_full_place(call_back.message.chat.id)
            answer = func.create_schedule_answer(day, full_place,
                                                 call_back.message.chat.id)
            if "Выходной" in answer:
                continue
            if json_week["Days"].index(day) == 0 or not is_send:
                try:
                    bot.edit_message_text(text=answer,
                                          chat_id=user_id,
                                          message_id=bot_msg.message_id,
                                          parse_mode="HTML")
                except ApiException:
                    func.send_long_message(bot, answer, user_id)
            else:
                func.send_long_message(bot, answer, user_id)
            is_send = True
    if not is_send or not len(json_week["Days"]):
        answer = "{0} Выходная неделя".format(emoji["sleep"])
        bot.edit_message_text(text=answer,
                              chat_id=user_id,
                              message_id=bot_msg.message_id)
示例#11
0
def schedule_handler(message):
    answer = f.create_answer("schedule", f.is_schedule(message.text.lower()).groups())
    f.send_long_message(bot=bot,
                        chat_id=message.chat.id,
                        text=answer)
示例#12
0
def search_handler(message):
    answer = f.create_answer("search", f.is_search(message.text.lower()).groups())
    f.send_long_message(bot=bot,
                        chat_id=message.chat.id,
                        text=answer)
示例#13
0
def location_handler(message):
    location = message.location
    answer = f.create_answer("nearest_stations", (location.latitude, location.longitude))
    f.send_long_message(bot=bot,
                        chat_id=message.chat.id,
                        text=answer)
示例#14
0
def other_text_handler(message):
    bot.send_chat_action(message.chat.id, "typing")
    answer = "Не понимаю"
    func.send_long_message(bot, answer, message.chat.id)