Download insert_from_file.py from hrrbb/ruhi: direct link, hf CLI and curl.
- Browser
- Download file 919 Bytes
-
https://huggingface.co/spaces/hrrbb/ruhi/resolve/main/insert_from_file.py
- Command line
-
hf download hf://spaces/hrrbb/ruhi/insert_from_file.py
-
curl -L -o insert_from_file.py https://huggingface.co/spaces/hrrbb/ruhi/resolve/main/insert_from_file.py
919 Bytes
| # backend/insert_from_file.py | |
| import asyncio | |
| import json | |
| import sys | |
| from pathlib import Path | |
| # Add parent directory to Python path | |
| BASE_DIR = Path(__file__).parent | |
| sys.path.append(str(BASE_DIR)) | |
| from scripts.insert_data import insert_entry # Import from scripts | |
| async def main(): | |
| try: | |
| # Read JSON with UTF-8 encoding | |
| with open('insert.json', 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| # Process all categories | |
| for entry_type in ["verses", "hadiths", "duas"]: | |
| collection_name = entry_type.rstrip('s') # Convert "verses" to "verse" | |
| for item in data.get(entry_type, []): | |
| await insert_entry(item, collection_name) | |
| print("✅ All insertions successful") | |
| except Exception as e: | |
| print(f"❌ Error: {str(e)}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |