Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
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
Beispiel #7
0
def inline_query_weekday_schedule_handler(inline_query):
    user_id = inline_query.from_user.id
    week_day = inline_query.query.title()

    day_date = func.get_day_date_by_weekday_title(week_day)
    json_day = func.get_json_day_data(user_id, day_date)
    full_place = func.is_full_place(user_id)
    answer = func.create_schedule_answer(json_day, full_place, user_id)

    group_info = func.get_current_group(user_id)

    week_num = (datetime.today() + server_timedelta).isocalendar()[1]

    r = InlineQueryResultArticle(
        id="{0}_{1}_{2}_{3}".format(user_id, group_info[0], week_num,
                                    week_day_number[week_day]),
        title=answer.split("\n\n")[0],
        input_message_content=InputTextMessageContent(
            answer, parse_mode="HTML"
        ),
        description=group_info[1]
    )
    bot.answer_inline_query(inline_query.id, [r], cache_time=1,
                            is_personal=True)