Skip to content

Instantly share code, notes, and snippets.

@Donluigimx
Created June 4, 2020 16:09
Show Gist options
  • Select an option

  • Save Donluigimx/f4395730237ee6360741df7901029a41 to your computer and use it in GitHub Desktop.

Select an option

Save Donluigimx/f4395730237ee6360741df7901029a41 to your computer and use it in GitHub Desktop.
const bent = require('bent');
const parser = require('csv-parser')
const fs = require('fs')
const pino = require("pino");
const destination = pino.destination("./app.log");
const pinoConfig = { name: "image-uploader" };
const log = pino(pinoConfig, destination);
const imagesServer = bent('https://wiggot.com/upload', 'json', 200, 'POST')
const results = []
fs.createReadStream('query_images.csv')
.pipe(parser())
.on('data', async (row) => {
results.push(row)
})
.on('end', async () => {
for (const image_data of results) {
const image_id = image_data.image_id
log.info({ image_id }, 'Modifying image')
try {
response = await imagesServer(`/image/${image_id}/fix`)
log.info({ response, image_id }, 'Image modified')
} catch (err) {
log.info({ image_id, err },'Error throwed while trying to modify an image')
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment