40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { scrapeCategory, saveProducts } from './src/services/scraper';
|
|
import { pool } from './src/db/migrate';
|
|
|
|
async function test() {
|
|
try {
|
|
console.log('Testing scraping Flower category (ID 85) for store 18...\n');
|
|
|
|
const storeId = 18;
|
|
const categoryId = 85; // Flower category
|
|
|
|
console.log('Step 1: Scraping products from Flower category...');
|
|
const products = await scrapeCategory(storeId, categoryId);
|
|
|
|
console.log(`\nStep 2: Scraped ${products.length} products. Saving to database...`);
|
|
await saveProducts(storeId, categoryId, products);
|
|
|
|
console.log('\nStep 3: Checking brands extracted from products...');
|
|
const brandsResult = await pool.query(`
|
|
SELECT DISTINCT brand
|
|
FROM products
|
|
WHERE store_id = $1 AND category_id = $2 AND brand IS NOT NULL
|
|
ORDER BY brand
|
|
`, [storeId, categoryId]);
|
|
|
|
console.log(`\nFound ${brandsResult.rows.length} unique brands:`);
|
|
brandsResult.rows.forEach(row => {
|
|
console.log(` - ${row.brand}`);
|
|
});
|
|
|
|
await pool.end();
|
|
console.log('\n✅ Test completed successfully!');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('\n❌ Error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
test();
|