def find_all_events_for_day(self, dt: datetime): all_busy_hours = [] all_clients = self.get_all_clients() for client in all_clients: date = DateHelper.get_date_from_string(client[3]) if date.year == dt.year and date.month == dt.month and date.day == dt.day: lower = client[4] upper = client[5] session_hours = [x for x in range(lower, upper)] all_busy_hours = all_busy_hours + session_hours available_hours = DateHelper.return_available_hours(all_busy_hours) print(f"Available hours are: {available_hours}") return available_hours
async def process_name(callback_query: CallbackQuery, callback_data: dict, state: FSMContext): selected, date = await process_calendar_selection(callback_query, callback_data) if selected: print(date) picked_date = date.strftime("%d.%m.%Y") await callback_query.message.answer( f"{Dialog.you_picked_day} {picked_date}") # check available time for event day_is_ok = DateHelper.day_is_correct(date) if not day_is_ok: await callback_query.message.answer(Dialog.pick_another_day, reply_markup=create_calendar()) return available_hours = db.find_all_events_for_day(date) if not available_hours: await callback_query.message.answer(Dialog.no_available_date, reply_markup=create_calendar()) return # proceed if date is correct and there are available hours hours_markup = return_inline_buttons_for_hours(available_hours) await callback_query.message.answer(Dialog.pick_hour, reply_markup=hours_markup) await state.update_data({"date": f"{date}"}) await RegistrationState.next()
async def ask_username(message: types.Message, state: FSMContext): user_data = await state.get_data() user_name = message.text user_phone = user_data["phone"] start_hour = int(user_data["hour"]) end_hour = int(start_hour + 3) date = user_data["date"] res = DateHelper.get_formatted_date(date, start_hour) response = f'{Dialog.name_desc} {user_name}\n' \ f'{Dialog.phone_desc} {user_phone}\n' \ f'{Dialog.date_desc} {res}' await message.answer(response) await state.finish() await state.reset_state(with_data=True) user_id = message.chat.id client_added = db.add_client(user_id=user_id, phone=user_phone, creation_date=f"{datetime.now()}", registration_date=date, start=start_hour, end=end_hour, user_name=user_name, deposit=0) print(client_added) await message.answer(Dialog.thanks_for_registration) for admin in admins: await dp.bot.send_message( chat_id=admin, text=f"{user_name} только что записался на сеанс.")
def get_description(user_id: int): client = db.get_client(user_id) date = DateHelper.get_formatted_date(client[3], client[4]) + f"-{client[5]}:00" phone = client[1] name = client[6] deposit = "Нет" if client[7] == 0 else "Да" res = f"Имя: {name}\nТелефон: {phone}\nДата записи: {date}\nЗалог внесен: {deposit}" return res
def find_all_events_in_range(self): lower = datetime.now() upper = datetime(lower.year + 1, lower.month, lower.day) all_clients = self.get_all_clients() filtered = [] for client in all_clients: date = DateHelper.get_date_from_string(client[3]) if lower < date < upper: filtered.append(client) return filtered
async def open_calendar(message: types.Message): user_id = message.chat.id client_has_appointment = db.check_if_user_has_appointment(user_id) if client_has_appointment: await message.answer(Dialog.already_have_appointment) client = db.get_client(user_id) if client: registered_date = client[3] session_start = client[4] res = DateHelper.get_formatted_date(registered_date, session_start) await message.answer(Dialog.date_desc + " " + res) else: await message.answer(Dialog.opening_calendar, reply_markup=ReplyKeyboardRemove()) await message.answer(Dialog.pick_date, reply_markup=create_calendar()) await RegistrationState.picking_date.set()
def check_if_user_has_appointment(self, user_id: int): clients = self.get_all_clients() if not clients: return False client = list(filter(lambda x: x[0] == user_id, clients)) if not client: return False client = client[0] session_date = client[3] session_start = client[4] dt = DateHelper.get_date_from_string(session_date) registration_date = datetime(dt.year, dt.month, dt.day, int(session_start)) current_date = datetime.now() if registration_date < current_date: self.delete_the_user(user_id) return False if registration_date > current_date: return True return False
from helpers.date_helper import DateHelper from helpers.date_formatter import DateFormatter DateHelper = DateHelper()