Exemplo n.º 1
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.")
Exemplo n.º 2
0
    def __init__(self, sign_time):
        """
        Convert timestamp time to datetime time in a specific time zone.
        And assign it to the corresponding member variable.

        :param sign_time: A user time of timestamp value.
        """

        self.date_time = local_date_time(sign_time)

        self.month = str(self.date_time.month)
        self.date = str(self.date_time.day)
        self.min = str(self.date_time.minute)

        self.interval_en = "AM"

        self.hours = str(self.date_time.hour)
        if self.date_time.hour > 12:
            self.interval_en = "PM"
            self.hours = str(self.date_time.hour - 12)

        self.str_current_time_tick = str(sign_time)
        pos = self.str_current_time_tick.find(".")
        if pos != -1:
            self.str_current_time_tick = self.str_current_time_tick[:pos]
def deal_confirm_out(account_id, create_time, callback):
    """
    will be linked with the calendar internally, Check out 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-out time
    :return: Prompt message of successful check out.
    """
    pos = callback.find("time=")
    str_time = callback[pos + 5:]
    user_time = int(str_time)

    end_time = local_date_time(user_time)
    current_date = datetime.strftime(end_time, '%Y-%m-%d')

    info = get_schedule_by_user(account_id, current_date)
    if info is None:
        raise HTTPError(500, "Internal data error")
    schedule_id = info[0]
    begin_time_st = info[1]

    cur_time = local_date_time(create_time)
    begin_time = local_date_time(begin_time_st)

    fmt = _("{account}'s working hours on {date}")
    fmt1 = _("%A, %B %d")
    title = get_i18n_content_by_lang(
        fmt,
        "confirm_out",
        DEFAULT_LANG,
        fmt1=fmt1,
        account=get_user_info_by_account(account_id),
        date=end_time)
    modify_schedule(schedule_id, cur_time, end_time, begin_time, account_id,
                    title)

    modify_schedule_by_user(schedule_id, user_time)

    hours = int((user_time - begin_time_st) / 3600)
    min = int(((user_time - begin_time_st) % 3600) / 60)

    return [confirm_out_message(user_time, hours, min)]
Exemplo n.º 4
0
def deal_confirm_out(account_id, create_time, callback):
    """
    will be linked with the calendar internally, Check out 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-out time
    :return: Prompt message of successful check out.
    """
    pos = callback.find("time=")
    str_time = callback[pos+5:]
    user_time = int(str_time)

    end_time = local_date_time(user_time)
    current_date = datetime.strftime(end_time, '%Y-%m-%d')

    info = get_schedule_by_user(account_id, current_date)
    if info is None:
        raise HTTPError(500, "Internal data error")
    schedule_id = info[0]
    begin_time_st = info[1]

    cur_time = local_date_time(create_time)
    begin_time = local_date_time(begin_time_st)

    title = "[{account}]'s working hours on {date}".\
        format(account=get_user_info_by_account(account_id),
               date=datetime.strftime(end_time, '%A, %B %d'))
    modify_schedule(schedule_id, cur_time, end_time, begin_time,
                    account_id, title)

    modify_schedule_by_user(schedule_id, user_time)

    if user_time < begin_time_st:
        yield asyncio.sleep(1)
        set_status_by_user_date(account_id, current_date, status="wait_out")
        return number_message(), False

    hours = int((user_time - begin_time_st)/3600)
    min = int(((user_time - begin_time_st) % 3600)/60)

    return [confirm_out_message(user_time, hours, min)], True
Exemplo n.º 5
0
def deal_user_message(account_id, current_date, create_time, message):
    """
    Process messages entered by users,
    Different scenarios need different processing functions.
    Please see the internal implementation of the handler.

    :param account_id: user account id.
    :param current_date: current date by local time.
    :param create_time: Time when the user requests to arrive at the BOT server.
    :param message: User entered message.
    :return: message content
    """

    date_time = local_date_time(create_time)

    content = get_status_by_user(account_id, current_date)

    if content is None or content[0] is None:
        LOGGER.info("status is None account_id:%s message:%s content:%s",
                    account_id, message, str(content))
        raise HTTPError(403, "Messages not need to be processed")

    status = content[0]
    process = content[1]
    try:
        user_time = int(message)
    except Exception:
        if status == "wait_in" or status == "wait_out":
            return error_message()
        else:
            raise HTTPError(403, "Messages not need to be processed")

    if (status == "wait_in" or status == "wait_out") \
            and (user_time < 0 or user_time > 2400):
        return error_message()

    tm = date_time.replace(hour=int(user_time / 100),
                           minute=int(user_time % 100))
    user_time_ticket = int(tm.timestamp())

    if status == "wait_in":
        content = yield deal_sign_in(account_id,
                                     current_date, user_time_ticket, True)
        set_status_by_user_date(account_id, current_date, status="in_done")
        return [content]
    if status == "wait_out":
        content = yield deal_sign_out(account_id,
                                      current_date, user_time_ticket, True)
        set_status_by_user_date(account_id, current_date, status="out_done")
        return [content]
    if process == "sign_in_done" or process == "sign_out_done":
        return [invalid_message()]

    LOGGER.info("can't deal this message account_id:%s message:%s status:%s",
                account_id, message, status)
    raise HTTPError(403, "Messages not need to be processed")
    def __init__(self, sign_time):
        """
        Convert timestamp time to datetime time in a specific time zone.
        And assign it to the corresponding member variable.

        :param sign_time: A user time of timestamp value.
        """

        self.date_time = local_date_time(sign_time)
        self.str_current_time_tick = str(sign_time)
        pos = self.str_current_time_tick.find(".")
        if pos != -1:
            self.str_current_time_tick = self.str_current_time_tick[:pos]
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)
Exemplo n.º 8
0
 def __init__(self):
     self.__create_time = time.time()
     date_time = local_date_time(self.__create_time)
     self.__current_date = datetime.strftime(date_time, '%Y-%m-%d')