← back to NEW SKU Viewer

fix-vendor-urls.js

60 lines

#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// Read all vendor .md files and extract correct URLs
const vendorMdDir = '/root/Projects/Designer-Wallcoverings/DW-Programming/ImportNewSkufromURL/vendor-md';
const vendorConfig = {};

// Parse vendor .md files
const mdFiles = fs.readdirSync(vendorMdDir).filter(f => f.endsWith('.md'));

mdFiles.forEach(file => {
  const vendorId = file.replace('.md', '');
  const content = fs.readFileSync(path.join(vendorMdDir, file), 'utf8');
  
  // Extract URLs from markdown
  const newProductsMatch = content.match(/- \*\*New Products URL\*\*: (.+)/);
  const catalogMatch = content.match(/- \*\*Catalog URL\*\*: (.+)/);
  const websiteMatch = content.match(/- \*\*Website\*\*: (.+)/);
  const nameMatch = content.match(/- \*\*Name\*\*: (.+)/);
  const waitTimeMatch = content.match(/- \*\*Wait Time\*\*: (.+)/);
  const platformMatch = content.match(/- \*\*Platform\*\*: (.+)/);
  
  vendorConfig[vendorId] = {
    id: vendorId,
    name: nameMatch ? nameMatch[1] : vendorId,
    website: websiteMatch ? websiteMatch[1] : '',
    newProductsUrl: newProductsMatch ? newProductsMatch[1] : '',
    catalogUrl: catalogMatch ? catalogMatch[1] : '',
    platform: platformMatch ? platformMatch[1] : '',
    waitTime: waitTimeMatch ? waitTimeMatch[1] : '5 seconds',
    scraperAvailable: true
  };
  
  // Use best available URL
  if (!vendorConfig[vendorId].newProductsUrl || vendorConfig[vendorId].newProductsUrl === 'Not configured') {
    vendorConfig[vendorId].newProductsUrl = vendorConfig[vendorId].catalogUrl || vendorConfig[vendorId].website;
  }
  if (!vendorConfig[vendorId].catalogUrl || vendorConfig[vendorId].catalogUrl === 'Not configured') {
    vendorConfig[vendorId].catalogUrl = vendorConfig[vendorId].newProductsUrl || vendorConfig[vendorId].website;
  }
});

// Save the correct vendor configuration
const outputFile = '/root/Projects/NEW-SKU-Viewer/vendor-config-fixed.json';
fs.writeFileSync(outputFile, JSON.stringify(vendorConfig, null, 2));

console.log(`✅ Fixed vendor configuration for ${Object.keys(vendorConfig).length} vendors`);
console.log(`📁 Saved to: ${outputFile}`);

// Show sample vendors
const samples = Object.values(vendorConfig).slice(0, 5);
console.log('\n📊 Sample vendor configurations:');
samples.forEach(v => {
  console.log(`\n${v.name}:`);
  console.log(`  URL: ${v.newProductsUrl}`);
  console.log(`  Platform: ${v.platform}`);
  console.log(`  Wait: ${v.waitTime}`);
});