Created
November 26, 2015 20:24
-
-
Save killroy42/1c5987a9cae2c088d141 to your computer and use it in GitHub Desktop.
This file contains 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
function fetchRemoteImage(id) { | |
console.log('fetchRemoteImage(%s);', id); | |
var card = cards[id]; | |
if(card === undefined) throw new Error('Card "'+id+'" not found.'); | |
var url = 'http://hearthstone.gamepedia.com/'+encodeURIComponent(card.name.replace(/ /g, '_')); | |
return fetch(url) | |
.then(function(body) { | |
var m = body.toString('utf8').match(/<img alt="" src="([^"]+)" width="[^"]+" height="[^"]+" class="thumbimage"/); | |
var url = m[1].replace(/(\?.*)/, ''); | |
m = url.match(/\.(png|jpg)$/); | |
fileName = fileBase + m[0]; | |
return fetch(url); | |
}) | |
.then(function(body) { | |
return fs.writeFileAsync(fileName, body, {encoding: 'ascii'}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks 😄