45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
from django.core.management.base import BaseCommand
|
|
from core.models import GameProject
|
|
from core.views import generate_game_script
|
|
from core.pexels import fetch_first
|
|
import time
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Ativa todos os jogos, gera scripts de IA e capas automaticamente para todo o catálogo.'
|
|
|
|
def handle(self, *args, **options):
|
|
games = GameProject.objects.all()
|
|
self.stdout.write(f"Iniciando atualização de {games.count()} jogos...")
|
|
|
|
for game in games:
|
|
self.stdout.write(f"Processando: {game.title}...")
|
|
|
|
# 1. Ativar o jogo
|
|
game.is_active = True
|
|
|
|
# 2. Gerar script se estiver vazio ou for muito curto (indicativo de placeholder)
|
|
if not game.script_code or len(game.script_code) < 100:
|
|
if not game.external_url:
|
|
self.stdout.write(f" -> Gerando script de IA para {game.title}...")
|
|
script = generate_game_script(game.title, game.prompt, game.genre)
|
|
if script:
|
|
game.script_code = script
|
|
else:
|
|
self.stdout.write(self.style.ERROR(f" -> Falha ao gerar script para {game.title}"))
|
|
|
|
# 3. Gerar Capa se não tiver
|
|
if not game.image_reference:
|
|
self.stdout.write(f" -> Buscando capa no Pexels para {game.title}...")
|
|
pexels_data = fetch_first(f"{game.title} game {game.genre}")
|
|
if pexels_data:
|
|
game.image_reference = pexels_data['local_path'].replace('media/', '')
|
|
else:
|
|
self.stdout.write(self.style.WARNING(f" -> Capa não encontrada para {game.title}"))
|
|
|
|
game.save()
|
|
self.stdout.write(self.style.SUCCESS(f" -> {game.title} ATUALIZADO E ATIVO!"))
|
|
|
|
# Pequena pausa para evitar sobrecarga na API de IA/Pexels
|
|
time.sleep(1)
|
|
|
|
self.stdout.write(self.style.SUCCESS("Processamento concluído com sucesso! Todos os jogos estão online.")) |