Skip to content

Instantly share code, notes, and snippets.

@killroy42
Created November 26, 2015 20:24
Show Gist options
  • Save killroy42/1c5987a9cae2c088d141 to your computer and use it in GitHub Desktop.
Save killroy42/1c5987a9cae2c088d141 to your computer and use it in GitHub Desktop.
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'});
});
}
@atticoos
Copy link

Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment