pounce/backend/scripts/seed_tld_prices.py
yves.gugger 5ac5643cd2 feat: add TLD price export/import/seed scripts
- export_tld_prices.py: Export DB prices to JSON
- import_tld_prices.py: Import prices from JSON
- seed_tld_prices.py: Initial scrape from Porkbun API
- tld_prices_export.json: Current price data (886 TLDs)

Usage:
  python scripts/seed_tld_prices.py     # Initial scrape
  python scripts/export_tld_prices.py   # Backup to JSON
  python scripts/import_tld_prices.py   # Restore from JSON
2025-12-08 09:16:33 +01:00

47 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Seed TLD prices by running a scrape from Porkbun API."""
import asyncio
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from app.database import AsyncSessionLocal, init_db
from app.services.tld_scraper.aggregator import tld_aggregator
async def seed_prices():
"""Run initial TLD price scrape."""
print("Initializing database...")
await init_db()
print("Starting TLD price scrape from Porkbun API...")
print("This may take 15-30 seconds...")
async with AsyncSessionLocal() as db:
result = await tld_aggregator.run_scrape(db)
print()
print("=" * 50)
print("Seed Results:")
print(f" Status: {result.status}")
print(f" TLDs scraped: {result.tlds_scraped}")
print(f" Prices saved: {result.prices_saved}")
print(f" Sources: {result.sources_succeeded}/{result.sources_attempted}")
if result.errors:
print(f" Errors: {result.errors}")
print("=" * 50)
if result.status == "success":
print("\n✅ TLD prices seeded successfully!")
else:
print("\n⚠️ Seed completed with warnings")
if __name__ == "__main__":
asyncio.run(seed_prices())