Created
May 26, 2018 17:07
-
-
Save afontcu/cee4c4485e1880a92c7263863c5d7405 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 fs = require('fs') | |
const request = require('request') | |
const download = (uri, filename, callback) => { | |
request.head(uri, (err, res, body) => { | |
if (err) throw err | |
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback) | |
}) | |
} | |
fs.readFile('data/data.json', 'utf8', (err, data) => { | |
if (err) throw err | |
const resources = JSON.parse(data).resources | |
Object.values(resources).forEach(({ name, image }) => { | |
if (image) { | |
const extension = image.split('.').pop() | |
const normalizedName = name.replace(/\W+/g, '-').toLowerCase() | |
const filename = `assets/logos/${normalizedName}.${extension}` | |
download(image, filename, () => { console.log('done') }) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment