def start(msg: types.Message) -> None:
    db.set_start_page_or_ignore(msg.chat.id)

    location = db.return_value_from_DB(table="users",
                                       field="location",
                                       pivot="tg_user_id",
                                       pivot_value=msg.chat.id)

    if not location:
        bot.send_message(msg.chat.id, "*Enter your location for job search:*")
        db.change_value_in_DB(table="users",
                              field_to_update="page",
                              field_to_update_value="input_location",
                              pivot="tg_user_id",
                              pivot_value=msg.chat.id)
    else:
        bot.send_message(
            msg.chat.id,
            consts.START_MESSAGE,
            reply_markup=utils.create_inline_keyboard_markup(
                kb=consts.START_KB),
        )
        db.change_value_in_DB(table="users",
                              field_to_update="page",
                              field_to_update_value="start",
                              pivot="tg_user_id",
                              pivot_value=msg.chat.id)
def change_location_from_inlinekb(call: types.CallbackQuery) -> None:
    bot.send_message(call.message.chat.id,
                     "*Enter your location for job search:*")
    db.change_value_in_DB(table="users",
                          field_to_update="page",
                          field_to_update_value="input_location",
                          pivot="tg_user_id",
                          pivot_value=call.message.chat.id)

    bot.answer_callback_query(call.id)
def search_vacancy_in_online_from_inlinekb(call: types.CallbackQuery) -> None:
    location = db.return_value_from_DB(table="users",
                                       field="location",
                                       pivot="tg_user_id",
                                       pivot_value=call.message.chat.id)

    bot.send_message(call.message.chat.id,
                     "*Enter the vacancy you are interested in:*")
    db.change_value_in_DB(table="users",
                          field_to_update="page",
                          field_to_update_value="input_vacancy",
                          pivot="tg_user_id",
                          pivot_value=call.message.chat.id)

    bot.answer_callback_query(call.id)
def send_inlinekb_for_employer(call: types.CallbackQuery) -> None:
    bot.edit_message_text(
        chat_id=call.message.chat.id,
        message_id=call.message.message_id,
        text=consts.EMPLOYER_MESSAGE,
        reply_markup=utils.create_inline_keyboard_markup(kb=consts.EMPLOYER_KB,
                                                         page="start"),
    )

    db.change_value_in_DB(table="users",
                          field_to_update="page",
                          field_to_update_value="employer",
                          pivot="tg_user_id",
                          pivot_value=call.message.chat.id)

    bot.answer_callback_query(call.id)
def set_value_for_vacancy(call: types.CallbackQuery) -> None:
    value_to_set = call.data.split("_")[1]

    text: str

    if value_to_set == "title":
        text = "*Enter a title for the job:*"
    elif value_to_set == "info":
        text = "*Enter vacancy description:*"
    elif value_to_set == "location":
        text = "*Enter the location of the vacancy:*"
    elif value_to_set == "contacts":
        text = "*Enter the contacts of your organization:*"

    bot.send_message(call.message.chat.id, text)

    db.change_value_in_DB(
        table="users",
        field_to_update="page",
        field_to_update_value=f"input_vacancies_{value_to_set}",
        pivot="tg_user_id",
        pivot_value=call.message.chat.id)

    bot.answer_callback_query(call.id)
Esempio n. 6
0
def all_text(msg: types.Message) -> None:
    page = db.return_value_from_DB(table="users",
                                   field="page",
                                   pivot="tg_user_id",
                                   pivot_value=msg.chat.id)

    if page.startswith("input"):
        type_of_value_to_input = page.split("_", 1)[1]

        if type_of_value_to_input == "location":
            db.change_value_in_DB(table="users",
                                  field_to_update="location",
                                  field_to_update_value=msg.text.lower(),
                                  pivot="tg_user_id",
                                  pivot_value=msg.chat.id)

            bot.send_message(msg.chat.id, "Your Location updated successfully")

            bot.send_message(
                msg.chat.id,
                consts.START_MESSAGE,
                reply_markup=utils.create_inline_keyboard_markup(
                    kb=consts.START_KB, group=msg.text),
            )
            db.change_value_in_DB(table="users",
                                  field_to_update="page",
                                  field_to_update_value="start",
                                  pivot="tg_user_id",
                                  pivot_value=msg.chat.id)
        elif type_of_value_to_input == "vacancy":
            location = db.return_value_from_DB(table="users",
                                               field="location",
                                               pivot="tg_user_id",
                                               pivot_value=msg.chat.id)

            vacancies = work_ua.work(msg.text, location)

            if vacancies:
                msg_for_user: str = ""

                for vacancy in vacancies.values():
                    msg_for_user += f"[{vacancy['title']}]({vacancy['href']})\n{vacancy['info'].strip()}\n\n"

                bot.send_message(msg.chat.id,
                                 msg_for_user,
                                 disable_web_page_preview=True)
            else:
                bot.send_message(msg.chat.id,
                                 "Nothing found for your location")
                bot.send_message(
                    msg.chat.id,
                    consts.START_MESSAGE,
                    reply_markup=utils.create_inline_keyboard_markup(
                        kb=consts.START_KB, group=msg.text),
                )
                db.change_value_in_DB(table="users",
                                      field_to_update="page",
                                      field_to_update_value="start",
                                      pivot="tg_user_id",
                                      pivot_value=msg.chat.id)

        else:
            type_of_value_to_input = type_of_value_to_input.split("_")[1]

            db.change_value_in_DB(table="vacancies",
                                  field_to_update=type_of_value_to_input,
                                  field_to_update_value=msg.text.lower(),
                                  pivot="tg_user_id",
                                  pivot_value=msg.chat.id)
            bot.send_message(msg.chat.id,
                             "Information has been successfully updated")

            is_full = db.check_if_vacancy_is_full(msg.chat.id)

            if is_full:
                bot.send_message(msg.chat.id, "Vacancy successfully added")
                bot.send_message(
                    msg.chat.id,
                    consts.START_MESSAGE,
                    reply_markup=utils.create_inline_keyboard_markup(
                        kb=consts.START_KB),
                )
                db.insert_empty(msg.chat.id)