diff --git a/config/__pycache__/__init__.cpython-311.pyc b/config/__pycache__/__init__.cpython-311.pyc index 07b9b8e..2276652 100644 Binary files a/config/__pycache__/__init__.cpython-311.pyc and b/config/__pycache__/__init__.cpython-311.pyc differ diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc index 4c85067..281cd8f 100644 Binary files a/config/__pycache__/settings.cpython-311.pyc and b/config/__pycache__/settings.cpython-311.pyc differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index 67044e4..27d8853 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/__pycache__/wsgi.cpython-311.pyc b/config/__pycache__/wsgi.cpython-311.pyc index 4522bc8..05ab9ff 100644 Binary files a/config/__pycache__/wsgi.cpython-311.pyc and b/config/__pycache__/wsgi.cpython-311.pyc differ diff --git a/core/__pycache__/__init__.cpython-311.pyc b/core/__pycache__/__init__.cpython-311.pyc index 5aedc64..9ecccf5 100644 Binary files a/core/__pycache__/__init__.cpython-311.pyc and b/core/__pycache__/__init__.cpython-311.pyc differ diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index 0b6abcb..0071a6c 100644 Binary files a/core/__pycache__/admin.cpython-311.pyc and b/core/__pycache__/admin.cpython-311.pyc differ diff --git a/core/__pycache__/apps.cpython-311.pyc b/core/__pycache__/apps.cpython-311.pyc index c86bdb7..2f054bd 100644 Binary files a/core/__pycache__/apps.cpython-311.pyc and b/core/__pycache__/apps.cpython-311.pyc differ diff --git a/core/__pycache__/context_processors.cpython-311.pyc b/core/__pycache__/context_processors.cpython-311.pyc index 7bbd1d6..553b7b9 100644 Binary files a/core/__pycache__/context_processors.cpython-311.pyc and b/core/__pycache__/context_processors.cpython-311.pyc differ diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc index b2c311e..c041035 100644 Binary files a/core/__pycache__/forms.cpython-311.pyc and b/core/__pycache__/forms.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 2a224a6..db9c55c 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 7d8f35f..e74af67 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 873c581..5626a46 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/0001_initial.cpython-311.pyc b/core/migrations/__pycache__/0001_initial.cpython-311.pyc index 4cbd3af..353005b 100644 Binary files a/core/migrations/__pycache__/0001_initial.cpython-311.pyc and b/core/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/0002_lottery_ai_predictions_lottery_analysis_window.cpython-311.pyc b/core/migrations/__pycache__/0002_lottery_ai_predictions_lottery_analysis_window.cpython-311.pyc index 90e0e6e..fa35d95 100644 Binary files a/core/migrations/__pycache__/0002_lottery_ai_predictions_lottery_analysis_window.cpython-311.pyc and b/core/migrations/__pycache__/0002_lottery_ai_predictions_lottery_analysis_window.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/0003_alter_lottery_name.cpython-311.pyc b/core/migrations/__pycache__/0003_alter_lottery_name.cpython-311.pyc index 2b3811c..553580d 100644 Binary files a/core/migrations/__pycache__/0003_alter_lottery_name.cpython-311.pyc and b/core/migrations/__pycache__/0003_alter_lottery_name.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/__init__.cpython-311.pyc b/core/migrations/__pycache__/__init__.cpython-311.pyc index debfaca..8cc8e92 100644 Binary files a/core/migrations/__pycache__/__init__.cpython-311.pyc and b/core/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/restore_app.py b/restore_app.py new file mode 100644 index 0000000..597b18a --- /dev/null +++ b/restore_app.py @@ -0,0 +1,87 @@ +import os +import django +import requests +from datetime import datetime + +# Setup Django environment +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') +django.setup() + +from core.models import Lottery, DrawResult, AdminAccess + +def restore_lotteries(): + lotteries_data = [ + ('mega_sena', 1, 60, 6), + ('quina', 1, 80, 5), + ('dupla_sena', 1, 50, 6), + ('lotomania', 0, 99, 50), + ('lotofacil', 1, 25, 15), + ('timemania', 1, 80, 7), + ('dia_de_sorte', 1, 31, 7), + ('federal', 0, 99999, 5), + ('super_sete', 0, 9, 7), + ('maismilionaria', 1, 50, 6), + ] + + for name, min_n, max_n, to_draw in lotteries_data: + Lottery.objects.get_or_create( + name=name, + defaults={ + 'min_number': min_n, + 'max_number': max_n, + 'numbers_to_draw': to_draw + } + ) + print("Loterias inicializadas.") + +def restore_admin(): + if not AdminAccess.objects.exists(): + admin = AdminAccess.objects.create(private_key='admin123') + print(f"Chave Admin criada: {admin.private_key}") + else: + print(f"Chave Admin existente: {AdminAccess.objects.first().private_key}") + +def sync_all_latest(): + from core.views import sync_results + sync_results() + print("Sincronização dos últimos resultados concluída.") + +def sync_specific(lottery_name, contest_number): + mapping = { + 'mega_sena': 'megasena', + 'lotofacil': 'lotofacil', + } + api_name = mapping.get(lottery_name) + if not api_name: return + + lottery = Lottery.objects.get(name=lottery_name) + try: + url = f"https://loteriascaixa-api.herokuapp.com/api/{api_name}/{contest_number}" + response = requests.get(url, timeout=5) + if response.status_code == 200: + data = response.json() + draw_number = int(data.get('concurso')) + if not DrawResult.objects.filter(lottery=lottery, draw_number=draw_number).exists(): + date_str = data.get('data') + draw_date = datetime.strptime(date_str, "%d/%m/%Y").date() + numbers_list = data.get('dezenas', []) + numbers_str = ",".join([str(int(n)) for n in numbers_list]) + DrawResult.objects.create( + lottery=lottery, + draw_number=draw_number, + draw_date=draw_date, + numbers=numbers_str + ) + print(f"Sincronizado específico: {lottery_name} Concurso {draw_number}") + except Exception as e: + print(f"Erro ao sincronizar {lottery_name} {contest_number}: {e}") + +if __name__ == "__main__": + restore_lotteries() + restore_admin() + sync_all_latest() + # Concursos solicitados na história + for contest in [2976, 2977]: + sync_specific('mega_sena', contest) + sync_specific('lotofacil', contest) + print("Restauração concluída!")