Files
koillection-uploader/image-downloader.js
T
joseph.nelson4456 c9f0d5a776
Build and Push Image / build-and-push (push) Successful in 1m16s
adding all images for perfect order to repo
2026-04-28 23:17:38 -07:00

31 lines
1.0 KiB
JavaScript

const fs = require('fs');
// Define the target directory for saving images
let imageDir = './master-set-images/perfect-order';
if (!fs.existsSync(imageDir)) {
fs.mkdirSync(imageDir);
}
// Read the CSV file line by line
const stream = fs.createReadStream('./csv/ME03PerfectOrderProductsAndPrices.csv');
let data = [];
stream.on('data', chunk => data.push(chunk));
stream.on('end', () => {
let rows = data.toString().split('\n').slice(1);
// Loop through each row (product) and download its image
rows.forEach(row => {
const columns = row.split(/[\t,]/).map(c => c.trim());
if (!!columns[3]) { // Image URL exists
let imgUrl = columns[3]; // Change image resolution
const fileName = columns[0]; // Get the file name (cleanName)
console.log(imgUrl);
fetch(imgUrl)
.then(res => res.arrayBuffer())
.then(buffer => fs.writeFileSync(`${imageDir}/${fileName}.jpg`, Buffer.from(buffer)))
.catch(err => console.error(err));
}
});
});