#!/usr/bin/env python3 """ Pre-download Quran data during HuggingFace Space build This runs once during deployment to cache all Quran text """ import asyncio import sys from pathlib import Path # Add src to path sys.path.insert(0, str(Path(__file__).parent)) from src.quran_data import download_full_quran, check_cached_data async def main(): print("=" * 60) print("PRE-LOADING QURAN DATA FOR HUGGINGFACE SPACE") print("=" * 60) # Check current cache status cache_info = check_cached_data() print(f"\nCurrent cache status:") print(f" Surahs cached: {cache_info['total_cached']}/114") print(f" Is complete: {cache_info['is_complete']}") if cache_info['is_complete']: print("\n✓ All Quran data already cached!") return print("\nDownloading all Quran text data...") print("Languages: Arabic (simple), English, Turkish") print("Size: ~2.7 MB") print("This will take about 2-3 minutes...\n") try: await download_full_quran() # Verify download final_cache = check_cached_data() print(f"\n✓ Download complete!") print(f" Total surahs cached: {final_cache['total_cached']}/114") print(f" Cache is complete: {final_cache['is_complete']}") if final_cache['is_complete']: print("\n🎉 SUCCESS: All Quran data is now cached and ready!") print(" The app will now work much faster!") else: print(f"\n⚠ WARNING: Only {final_cache['total_cached']} surahs cached") print(" Some data may need to be downloaded at runtime") except Exception as e: print(f"\n❌ ERROR during download: {e}") print(" App will fall back to downloading data at runtime") sys.exit(0) # Don't fail the build, just warn if __name__ == "__main__": asyncio.run(main())