diff --git a/backend/scripts/sync_all_zones.py b/backend/scripts/sync_all_zones.py index 0340c24..727f919 100644 --- a/backend/scripts/sync_all_zones.py +++ b/backend/scripts/sync_all_zones.py @@ -62,21 +62,16 @@ SWITCH_CONFIG = { } } -# Setup logging (avoid duplicate handlers) -logger = logging.getLogger("pounce_zone_sync") -logger.setLevel(logging.INFO) -if not logger.handlers: - formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') - console = logging.StreamHandler() - console.setFormatter(formatter) - logger.addHandler(console) - try: - LOG_FILE.parent.mkdir(parents=True, exist_ok=True) - file_handler = logging.FileHandler(LOG_FILE) - file_handler.setFormatter(formatter) - logger.addHandler(file_handler) - except Exception: - pass +# Setup logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s [%(levelname)s] %(message)s', + handlers=[ + logging.StreamHandler(), + logging.FileHandler(LOG_FILE) if LOG_FILE.parent.exists() else logging.StreamHandler() + ] +) +logger = logging.getLogger(__name__) class ZoneSyncResult: @@ -86,39 +81,15 @@ class ZoneSyncResult: self.success = False self.domain_count = 0 self.drops_count = 0 - self.drops: list = [] # CRITICAL: List of (domain, tld) tuples for DB storage self.error: Optional[str] = None self.duration_seconds = 0 async def get_db_session(): - """Create async database session - ROBUST VERSION (reads .env directly)""" - # Read DATABASE_URL directly from .env to avoid import issues when running standalone - env_file = Path("/home/user/pounce/backend/.env") - if not env_file.exists(): - env_file = Path(__file__).parent.parent / ".env" + """Create async database session""" + from app.config import settings - db_url = None - if env_file.exists(): - for line in env_file.read_text().splitlines(): - if line.startswith("DATABASE_URL="): - db_url = line.split("=", 1)[1].strip().strip('"').strip("'") - break - - # Default to SQLite if not found - if not db_url: - db_url = "sqlite:///./domainwatch.db" - logger.warning(f"DATABASE_URL not found in .env, using default: {db_url}") - - # Convert to async driver - if "sqlite://" in db_url and "aiosqlite" not in db_url: - db_url = db_url.replace("sqlite://", "sqlite+aiosqlite://") - elif "postgresql://" in db_url and "asyncpg" not in db_url: - db_url = db_url.replace("postgresql://", "postgresql+asyncpg://") - - logger.info(f"DB connection: {db_url[:50]}...") - - engine = create_async_engine(db_url, echo=False) + engine = create_async_engine(settings.database_url.replace("sqlite://", "sqlite+aiosqlite://")) async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) return async_session() @@ -578,7 +549,7 @@ async def main(): results.append(result) # Store drops IMMEDIATELY after each TLD (crash-safe) - if result.drops: + if hasattr(result, 'drops') and result.drops: await store_tld_drops(result.drops, tld) # Rate limit: wait between downloads @@ -643,4 +614,4 @@ async def main(): if __name__ == "__main__": exit_code = asyncio.run(main()) - sys.exit(exit_code) + sys.exit(exit_code) \ No newline at end of file diff --git a/frontend/src/components/hunt/DropsTab.tsx b/frontend/src/components/hunt/DropsTab.tsx index 04fcca1..ae9dcc6 100644 --- a/frontend/src/components/hunt/DropsTab.tsx +++ b/frontend/src/components/hunt/DropsTab.tsx @@ -416,14 +416,14 @@ export function DropsTab({ showToast }: DropsTabProps) { {sortedItems.map((item) => ( -