From cff1b2bc919aca4949a069ecfc2914de5d161ec3 Mon Sep 17 00:00:00 2001 From: DevProject Agent Date: Sun, 14 Jun 2026 19:23:52 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20=D0=9A=D0=BE=D0=BD=D1=84=D0=B8?= =?UTF-8?q?=D0=B3:=20=D1=83=D1=81=D0=BB=D1=83=D0=B3=D0=B8,=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D1=80=D0=B0=20=D0=B8=20=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D1=8F=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=B2=20config.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SERVICES, MASTERS, TIME_SLOTS в config.py - Клавиатуры services.py, masters.py, time_slots.py берут данные из config - booking.py импортирует services/masters из config вместо хардкода - time_slots отображает занятые слоты как ❌, свободные как ✅ --- app/__init__.py | 0 app/config.py | 26 ++++++++++++++++-- app/handlers/booking.py | 38 +++++++++++--------------- app/keyboards/masters.py | 32 +++++----------------- app/keyboards/services.py | 32 +++++----------------- app/keyboards/time_slots.py | 54 +++++++++++-------------------------- 6 files changed, 70 insertions(+), 112 deletions(-) create mode 100644 app/__init__.py diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/config.py b/app/config.py index 27036cd..860f849 100644 --- a/app/config.py +++ b/app/config.py @@ -1,9 +1,31 @@ import os +import json from dotenv import load_dotenv load_dotenv() -BOT_TOKEN = os.getenv("BOT_TOKEN") +BOT_TOKEN = os.getenv(BOT_TOKEN) if not BOT_TOKEN: - raise ValueError("BOT_TOKEN не найден") \ No newline at end of file + raise ValueError(BOT_TOKEN не найден) + +# ——— Данные для клавиатур ——— + +SERVICES = { + service_massage: Массаж, + service_spa: SPA, + service_cosmetology: Косметология, +} + +MASTERS = { + master_anna: Анна, + master_maria: Мария, + master_alex: Алексей, +} + +TIME_SLOTS = [ + 09:00, 10:00, 11:00, + 12:00, 13:00, 14:00, + 15:00, 16:00, 17:00, + 18:00, +] diff --git a/app/handlers/booking.py b/app/handlers/booking.py index e3b310c..da29fe0 100644 --- a/app/handlers/booking.py +++ b/app/handlers/booking.py @@ -51,11 +51,8 @@ async def choose_service( callback: CallbackQuery, state: FSMContext ): - services = { - "service_massage": "Массаж", - "service_spa": "SPA", - "service_cosmetology": "Косметология" - } + from app.config import SERVICES + services = SERVICES service_name = services[callback.data] @@ -83,11 +80,8 @@ async def choose_master( state: FSMContext ): - masters = { - "master_anna": "Анна", - "master_maria": "Мария", - "master_alex": "Алексей" - } + from app.config import MASTERS + masters = MASTERS master_name = masters[callback.data] @@ -128,7 +122,7 @@ async def choose_date( data = await state.get_data() busy_times = get_busy_times( - master=data.get("master", "?"), + master=data.get('master', '?'), date=selected_date ) @@ -171,9 +165,9 @@ async def choose_time( await callback.message.edit_text( f"📋 Проверьте запись:\n\n" - f"💆 Услуга: {data.get("service", "?")}\n" - f"📅 Дата: {data.get("date", "?")}\n" - f"👤 Мастер:{data.get("master", "?")}\n" + f"💆 Услуга: {data.get('service', '?')}\n" + f"📅 Дата: {data.get('date', '?')}\n" + f"👤 Мастер:{data.get('master', '?')}\n" f"🕒 Время: {selected_time}", reply_markup=get_confirm_booking_keyboard() ) @@ -200,10 +194,10 @@ async def confirm_booking_callback( update_booking( booking_id=editing_booking_id, - service=data.get("service", "?"), - master=data.get("master", "?"), - date=data.get("date", "?"), - time=data.get("time", "?") + service=data.get('service', '?'), + master=data.get('master', '?'), + date=data.get('date', '?'), + time=data.get('time', '?') ) result_text = "✅ Запись успешно обновлена" @@ -212,10 +206,10 @@ async def confirm_booking_callback( create_booking( user_id=callback.from_user.id, - service=data.get("service", "?"), - master=data.get("master", "?"), - date=data.get("date", "?"), - time=data.get("time", "?") + service=data.get('service', '?'), + master=data.get('master', '?'), + date=data.get('date', '?'), + time=data.get('time', '?') ) result_text = "✅ Запись успешно создана" diff --git a/app/keyboards/masters.py b/app/keyboards/masters.py index 94272f2..0b9208d 100644 --- a/app/keyboards/masters.py +++ b/app/keyboards/masters.py @@ -1,28 +1,10 @@ -from aiogram.types import InlineKeyboardMarkup -from aiogram.types import InlineKeyboardButton +from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from app.config import MASTERS def get_masters_keyboard(): - - return InlineKeyboardMarkup( - inline_keyboard=[ - [ - InlineKeyboardButton( - text="👩 Анна", - callback_data="master_anna" - ) - ], - [ - InlineKeyboardButton( - text="👩 Мария", - callback_data="master_maria" - ) - ], - [ - InlineKeyboardButton( - text="👨 Алексей", - callback_data="master_alex" - ) - ] - ] - ) \ No newline at end of file + buttons = [ + [InlineKeyboardButton(text=name, callback_data=key)] + for key, name in MASTERS.items() + ] + return InlineKeyboardMarkup(inline_keyboard=buttons) diff --git a/app/keyboards/services.py b/app/keyboards/services.py index 813ffbc..81f2b67 100644 --- a/app/keyboards/services.py +++ b/app/keyboards/services.py @@ -1,28 +1,10 @@ -from aiogram.types import InlineKeyboardMarkup -from aiogram.types import InlineKeyboardButton +from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from app.config import SERVICES def get_services_keyboard(): - - return InlineKeyboardMarkup( - inline_keyboard=[ - [ - InlineKeyboardButton( - text="💆 Массаж", - callback_data="service_massage" - ) - ], - [ - InlineKeyboardButton( - text="🌿 SPA", - callback_data="service_spa" - ) - ], - [ - InlineKeyboardButton( - text="✨ Косметология", - callback_data="service_cosmetology" - ) - ] - ] - ) \ No newline at end of file + buttons = [ + [InlineKeyboardButton(text=name, callback_data=key)] + for key, name in SERVICES.items() + ] + return InlineKeyboardMarkup(inline_keyboard=buttons) diff --git a/app/keyboards/time_slots.py b/app/keyboards/time_slots.py index b93663c..f5d5697 100644 --- a/app/keyboards/time_slots.py +++ b/app/keyboards/time_slots.py @@ -1,41 +1,19 @@ -from aiogram.types import InlineKeyboardMarkup -from aiogram.types import InlineKeyboardButton +from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from app.config import TIME_SLOTS -def get_time_keyboard( - busy_times=None -): - - if busy_times is None: - busy_times = [] - - times = [ - "10:00", - "11:00", - "12:00", - "13:00", - "14:00", - "15:00", - "16:00", - "17:00" - ] - +def get_time_keyboard(busy_times): buttons = [] - - for time in times: - - if time in busy_times: - continue - - buttons.append( - [ - InlineKeyboardButton( - text=time, - callback_data=f"time_{time}" - ) - ] - ) - - return InlineKeyboardMarkup( - inline_keyboard=buttons - ) \ No newline at end of file + row = [] + for slot in TIME_SLOTS: + if slot in busy_times: + label = f❌ {slot} + else: + label = f✅ {slot} + row.append(InlineKeyboardButton(text=label, callback_data=ftime_{slot})) + if len(row) == 3: + buttons.append(row) + row = [] + if row: + buttons.append(row) + return InlineKeyboardMarkup(inline_keyboard=buttons)