ruhi / insert_from_file.py
hrrbb's picture
Add remaining project files
a37a364
Raw History Blame Contribute Delete
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())