const { Pool } = require('pg'); const pool = new Pool({ connectionString: process.env.DATABASE_URL || 'postgresql://kelly:kelly@localhost:5432/hub' }); (async () => { try { // Check for categories that have been scraped const historyResult = await pool.query(` SELECT s.id as store_id, s.name as store_name, c.id as category_id, c.name as category_name, c.last_scraped_at, ( SELECT COUNT(*) FROM products p WHERE p.store_id = s.id AND p.category_id = c.id ) as product_count FROM stores s LEFT JOIN categories c ON c.store_id = s.id WHERE c.last_scraped_at IS NOT NULL ORDER BY c.last_scraped_at DESC LIMIT 10 `); console.log('\nšŸ“Š Scraper History:'); console.log('='.repeat(80)); if (historyResult.rows.length === 0) { console.log('No scraper history found. No categories have been scraped yet.'); } else { historyResult.rows.forEach(row => { console.log(`\nStore: ${row.store_name} (ID: ${row.store_id})`); console.log(`Category: ${row.category_name} (ID: ${row.category_id})`); console.log(`Last Scraped: ${row.last_scraped_at}`); console.log(`Products: ${row.product_count}`); }); } // Check total categories const totalCategoriesResult = await pool.query(` SELECT COUNT(*) as total FROM categories `); console.log(`\n\nTotal Categories: ${totalCategoriesResult.rows[0].total}`); // Check categories with last_scraped_at const scrapedCategoriesResult = await pool.query(` SELECT COUNT(*) as scraped FROM categories WHERE last_scraped_at IS NOT NULL `); console.log(`Categories Scraped: ${scrapedCategoriesResult.rows[0].scraped}`); process.exit(0); } catch (error) { console.error('Error:', error); process.exit(1); } })();