🧹 Конфиг: услуги, мастера и время вынесены в config.py

- SERVICES, MASTERS, TIME_SLOTS в config.py
- Клавиатуры services.py, masters.py, time_slots.py берут данные из config
- booking.py импортирует services/masters из config вместо хардкода
- time_slots отображает занятые слоты как , свободные как 
This commit is contained in:
DevProject Agent
2026-06-14 19:23:52 +04:00
parent 8efd5d09d5
commit cff1b2bc91
6 changed files with 70 additions and 112 deletions
View File
+24 -2
View File
@@ -1,9 +1,31 @@
import os import os
import json
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
BOT_TOKEN = os.getenv("BOT_TOKEN") BOT_TOKEN = os.getenv(BOT_TOKEN)
if not BOT_TOKEN: if not BOT_TOKEN:
raise ValueError("BOT_TOKEN не найден") 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,
]
+16 -22
View File
@@ -51,11 +51,8 @@ async def choose_service(
callback: CallbackQuery, callback: CallbackQuery,
state: FSMContext state: FSMContext
): ):
services = { from app.config import SERVICES
"service_massage": "Массаж", services = SERVICES
"service_spa": "SPA",
"service_cosmetology": "Косметология"
}
service_name = services[callback.data] service_name = services[callback.data]
@@ -83,11 +80,8 @@ async def choose_master(
state: FSMContext state: FSMContext
): ):
masters = { from app.config import MASTERS
"master_anna": "Анна", masters = MASTERS
"master_maria": "Мария",
"master_alex": "Алексей"
}
master_name = masters[callback.data] master_name = masters[callback.data]
@@ -128,7 +122,7 @@ async def choose_date(
data = await state.get_data() data = await state.get_data()
busy_times = get_busy_times( busy_times = get_busy_times(
master=data.get("master", "?"), master=data.get('master', '?'),
date=selected_date date=selected_date
) )
@@ -171,9 +165,9 @@ async def choose_time(
await callback.message.edit_text( await callback.message.edit_text(
f"📋 Проверьте запись:\n\n" f"📋 Проверьте запись:\n\n"
f"💆 Услуга: {data.get("service", "?")}\n" f"💆 Услуга: {data.get('service', '?')}\n"
f"📅 Дата: {data.get("date", "?")}\n" f"📅 Дата: {data.get('date', '?')}\n"
f"👤 Мастер:{data.get("master", "?")}\n" f"👤 Мастер:{data.get('master', '?')}\n"
f"🕒 Время: {selected_time}", f"🕒 Время: {selected_time}",
reply_markup=get_confirm_booking_keyboard() reply_markup=get_confirm_booking_keyboard()
) )
@@ -200,10 +194,10 @@ async def confirm_booking_callback(
update_booking( update_booking(
booking_id=editing_booking_id, booking_id=editing_booking_id,
service=data.get("service", "?"), service=data.get('service', '?'),
master=data.get("master", "?"), master=data.get('master', '?'),
date=data.get("date", "?"), date=data.get('date', '?'),
time=data.get("time", "?") time=data.get('time', '?')
) )
result_text = "✅ Запись успешно обновлена" result_text = "✅ Запись успешно обновлена"
@@ -212,10 +206,10 @@ async def confirm_booking_callback(
create_booking( create_booking(
user_id=callback.from_user.id, user_id=callback.from_user.id,
service=data.get("service", "?"), service=data.get('service', '?'),
master=data.get("master", "?"), master=data.get('master', '?'),
date=data.get("date", "?"), date=data.get('date', '?'),
time=data.get("time", "?") time=data.get('time', '?')
) )
result_text = "✅ Запись успешно создана" result_text = "✅ Запись успешно создана"
+7 -25
View File
@@ -1,28 +1,10 @@
from aiogram.types import InlineKeyboardMarkup from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from aiogram.types import InlineKeyboardButton from app.config import MASTERS
def get_masters_keyboard(): def get_masters_keyboard():
buttons = [
return InlineKeyboardMarkup( [InlineKeyboardButton(text=name, callback_data=key)]
inline_keyboard=[ for key, name in MASTERS.items()
[ ]
InlineKeyboardButton( return InlineKeyboardMarkup(inline_keyboard=buttons)
text="👩 Анна",
callback_data="master_anna"
)
],
[
InlineKeyboardButton(
text="👩 Мария",
callback_data="master_maria"
)
],
[
InlineKeyboardButton(
text="👨 Алексей",
callback_data="master_alex"
)
]
]
)
+7 -25
View File
@@ -1,28 +1,10 @@
from aiogram.types import InlineKeyboardMarkup from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from aiogram.types import InlineKeyboardButton from app.config import SERVICES
def get_services_keyboard(): def get_services_keyboard():
buttons = [
return InlineKeyboardMarkup( [InlineKeyboardButton(text=name, callback_data=key)]
inline_keyboard=[ for key, name in SERVICES.items()
[ ]
InlineKeyboardButton( return InlineKeyboardMarkup(inline_keyboard=buttons)
text="💆 Массаж",
callback_data="service_massage"
)
],
[
InlineKeyboardButton(
text="🌿 SPA",
callback_data="service_spa"
)
],
[
InlineKeyboardButton(
text="✨ Косметология",
callback_data="service_cosmetology"
)
]
]
)
+16 -38
View File
@@ -1,41 +1,19 @@
from aiogram.types import InlineKeyboardMarkup from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from aiogram.types import InlineKeyboardButton from app.config import TIME_SLOTS
def get_time_keyboard( def get_time_keyboard(busy_times):
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"
]
buttons = [] buttons = []
row = []
for time in times: for slot in TIME_SLOTS:
if slot in busy_times:
if time in busy_times: label = f {slot}
continue else:
label = f {slot}
buttons.append( row.append(InlineKeyboardButton(text=label, callback_data=ftime_{slot}))
[ if len(row) == 3:
InlineKeyboardButton( buttons.append(row)
text=time, row = []
callback_data=f"time_{time}" if row:
) buttons.append(row)
] return InlineKeyboardMarkup(inline_keyboard=buttons)
)
return InlineKeyboardMarkup(
inline_keyboard=buttons
)