def deal_sign_out_message(sign_time, manual_flag=False):
    """
    Generate a message returned to the user when checking out.

    :param sign_time: The user's check-in time is a timestamp.
    :param manual_flag: Boolean value. True is manually enters time.
    :return: message content is a json.
    """
    call_back = "sign_out"
    if manual_flag:
        call_back = "manual_sign_out"

    user_time = TimeStruct(sign_time)

    text = make_text("Register the current time {date}".format(
        date=user_time.date_time.strftime('%A, %B %-d '
                                          'at %-I:%M %P')))

    if manual_flag:
        text = make_text(
            "Register the entered {date} as clock-out time?".format(
                date=user_time.date_time.strftime('%m, %-d %A '
                                                  'at %-I:%M %P')))

    reply_items = create_quick_replay_items(
        "confirm_out&time=" + user_time.str_current_time_tick, call_back)

    text["quickReply"] = make_quick_reply(reply_items)
    return text
Esempio n. 2
0
def deal_sign_in_message(sign_time, manual_flag):
    """
    Generate a message returned to the user when checking in.

    :param sign_time: The user's check-in time is a timestamp.
    :param manual_flag: Boolean value. True is manually enters time.
    :return: message content is a json.
    """
    call_back = "sign_in"
    if manual_flag:
        call_back = "manual_sign_in"

    user_time = TimeStruct(sign_time)

    text = make_text("Register the current time {date} at {hours}:{min} "
                     "{interval} as clock-in time?".format(
                         date=user_time.date_time.strftime('%m, %d %A'),
                         hours=user_time.hours,
                         min=user_time.min,
                         interval=user_time.interval_en))

    if manual_flag:
        text = make_text("Register the entered {date} at {hours}:{min} "
                         "{interval} as clock-in time?".format(
                             date=user_time.date_time.strftime('%m, %d %A'),
                             hours=user_time.hours,
                             min=user_time.min,
                             interval=user_time.interval_en))

    reply_items = create_quick_replay_items(
        "confirm_in&time=" + user_time.str_current_time_tick, call_back)

    text["quickReply"] = make_quick_reply(reply_items)

    return text
Esempio n. 3
0
def deal_confirm_in(account_id, create_time, callback):
    """
    will be linked with the calendar internally, Check in time of registered user.
    Check also: attendance_management_bot/externals/calendar_req.py

    :param account_id: user account id.
    :param create_time: current date by local time.
    :param callback: The message content of the callback,
        include the user's check-in time
    :return: Prompt message of successful check in.
    """
    pos = callback.find("time=")
    str_time = callback[pos + 5:]
    user_time = int(str_time)
    my_end_time = user_time + 60
    begin_time = local_date_time(user_time)
    current_date = datetime.strftime(begin_time, '%Y-%m-%d')

    info = get_schedule_by_user(account_id, current_date)
    if info is not None:
        raise HTTPError(500, "Internal data error")

    end_time = begin_time + timedelta(minutes=1)
    cur_time = local_date_time(create_time)
    title = "{account}'s clock-in time on {date}".\
        format(account=get_user_info_by_account(account_id),
               date=datetime.strftime(begin_time, '%A, %B %d'))
    schedule_uid = create_schedule(cur_time, end_time, begin_time, account_id,
                                   title)

    set_schedule_by_user(schedule_uid, account_id, current_date, user_time,
                         my_end_time)

    return make_text("Clock-in time has been registered.")
def confirm_out_message(user_time, hours, min):
    user_time = TimeStruct(user_time)

    return make_text("Clock-out time has been registered."
                     "The total working hours for {date} "
                     "is {hours} hours and {minutes} minutes."
                     .format(date=user_time.date_time.strftime('%A, %B %d'),
                             hours=hours, minutes=min))
Esempio n. 5
0
def start_content(account_id):
    yield sign(account_id)

    content1 = make_text("Hello, I'm an attendance management bot of "
                         "LINE WORKS that helps your timeclock "
                         "management and entry.")
    content2 = image_introduce()

    return [content1, content2]
Esempio n. 6
0
def prompt_input():
    """
    Format to remind users to enter time.

    :return: text type message
    """
    return make_text("Please use the military time format "
                     "with a total of 4 numerical digits (hhmm) "
                     "when entering the time."
                     "For example, type 2020 to indicate 8:20 PM. ")
Esempio n. 7
0
def invalid_message():
    """
    Invalid input data reminder.

    :return: text type message
    """
    return make_text("I didn't understand the text. "
                     "When you go to work or go home, "
                     "Please select the appropriate "
                     "\"Record\" button for each.")
Esempio n. 8
0
def manual_sign_out_message():
    """
    generate manual check-out message

    :return: message content list
    """
    text1 = make_text("Please manually enter the clock-out time.")

    text2 = prompt_input()

    return [text1, text2]
Esempio n. 9
0
def confirm_out_message(user_time, total_hours, total_minutes):
    user_time = TimeStruct(user_time)

    str_hours = ""
    if total_hours != 0:
        str_hours = "{total_hours} hours and ".format(total_hours=total_hours)
    return make_text("Clock-out time has been registered."
                     "The total working hours for {date} "
                     "is {total_hours}{total_minutes} minutes.".format(
                         date=user_time.date_time.strftime('%A, %B %d'),
                         total_hours=str_hours,
                         total_minutes=total_minutes))
Esempio n. 10
0
def number_message():
    """
    Non digital message entered.

    :return: text type message
    """
    text1 = make_text("You have created your leave time "
                      "earlier than your leave time. "
                      "Please check your work time and enter again.")

    text2 = prompt_input()
    return [text1, text2]
Esempio n. 11
0
def reminder_message(process):
    """
    Illegal request reminder.

    :param process: Current user's progress
    :return: text type message
    """
    text = None
    if process == "sign_in_done":
        text = make_text("There is already a clock-in time. "
                         "Please select \"Record\" on the "
                         "bottom of the menu when you clock out.")

    elif process == "sign_out_done":
        text = make_text("There is already a clock-out time."
                         "Please select \"Record\" on the bottom "
                         "of the menu when you clock in.")
    elif process is None:
        text = make_text("Today's clock-in time has not been registered. "
                         "Please select \"Record clock-in\" on the bottom "
                         "of the menu, and enter your clock-in time.")
    return text
Esempio n. 12
0
def error_message():
    """
    Wrong data entered

    :return: text type message
    """
    text1 = make_text("Sorry, but unable to "
                      "comprehend your composed time. "
                      "Please check the time entry method again, "
                      "and enter the time.")

    text2 = prompt_input()
    return [text1, text2]
def confirm_out_message(user_time, total_hours, total_minutes):
    date_time = local_date_time(user_time)

    fmt = _(" ")
    str_hours = ""
    hours_content = get_i18n_content(fmt, "confirm_out")

    if total_hours != 0:
        str_hours = "{total_hours} hours and "
        fmt = _("{total_hours} hours and ")
        hours_content = get_i18n_content(fmt, "confirm_out")
        for key in hours_content:
            hours_content[key] = hours_content[key].format(
                total_hours=total_hours)

    fmt1 = _(
        "Clock-out time has been registered. "
        "The total working hours for {date} is {total_hours}{total_minutes} minutes."
    )
    texts = get_i18n_content(fmt1, "confirm_out")

    fmt2 = _("%A, %B %d")
    dates = get_i18n_content(fmt2, "confirm_out")

    i18n_texts = []
    for key in texts:
        locale.setlocale(locale.LC_TIME, "{lang}{code}".format(lang=key,
                                                               code=".utf8"))
        value = texts[key].format(date=date_time.strftime(dates[key]),
                                  total_hours=hours_content[key],
                                  total_minutes=total_minutes)
        i18n_texts.append(i18n_text(key, value))

    locale.setlocale(locale.LC_TIME, "{lang}{code}".format(lang="en_US",
                                                           code=".utf8"))
    return make_text("Clock-out time has been registered. "
                     "The total working hours for {date} "
                     "is{total_hours}{total_minutes} minutes.".format(
                         date=date_time.strftime('%A, %B %d'),
                         total_hours=str_hours,
                         total_minutes=total_minutes),
                     i18n_texts=i18n_texts)
Esempio n. 14
0
def to_first(account_id, _, __, ___):
    content = make_text("Please select \"Record\" on the bottom of "
                        "the menu each time when you clock in and clock out.")
    yield push_message(account_id, content)