File size: 1,870 Bytes
006062c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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())