Created
June 4, 2020 16:09
-
-
Save Donluigimx/f4395730237ee6360741df7901029a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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