#!/usr/bin/env python3 """ Скрипт для добавления картинки к службе Использование: python3 update_service_image.py Пример: python3 update_service_image.py police data/service_images/police.jpg """ import sys import asyncio from pathlib import Path # Добавляем путь к проекту BASE_DIR = Path(__file__).resolve().parent.parent sys.path.insert(0, str(BASE_DIR)) from database.db import AsyncSessionLocal from database.models import Service from sqlalchemy import update async def update_service_image(category: str, image_path: str): """Обновить картинку службы""" # Проверяем что файл существует if not Path(image_path).exists(): print(f"❌ Файл не найден: {image_path}") return async with AsyncSessionLocal() as session: # Обновляем все службы этой категории result = await session.execute( update(Service) .where(Service.category == category) .values(image_path=image_path) ) await session.commit() updated_count = result.rowcount print(f"✅ Обновлёно записей: {updated_count}") print(f" Категория: {category}") print(f" Картинка: {image_path}") if __name__ == '__main__': if len(sys.argv) != 3: print("Использование: python3 update_service_image.py ") print("Пример: python3 update_service_image.py police data/service_images/police.jpg") sys.exit(1) category = sys.argv[1] image_path = sys.argv[2] asyncio.run(update_service_image(category, image_path))