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 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)]
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
def deal_sign_out(account_id, current_date, sign_time, manual_flag=False): content = get_status_by_user(account_id, current_date) process = None if content is not None: status = content[0] process = content[1] if process is None or process != "sign_in_done": return [invalid_message()], True if status == "wait_out" or status == "out_done": set_status_by_user_date(account_id, current_date, status="in_done") info = get_schedule_by_user(account_id, current_date) if info is None: raise HTTPError(500, "Internal data error") begin_time_st = info[1] user_time = TimeStruct(sign_time) if int(user_time.str_current_time_tick) < begin_time_st: set_status_by_user_date(account_id, current_date, status="wait_out") return number_message(), False return [deal_sign_out_message(sign_time, manual_flag)], True