Skip to content

Instantly share code, notes, and snippets.

@unixfox
Last active May 15, 2020 16:40
Show Gist options
  • Save unixfox/2014fc787b8950103070e82dd941e92e to your computer and use it in GitHub Desktop.
Save unixfox/2014fc787b8950103070e82dd941e92e to your computer and use it in GitHub Desktop.
get random skins from namemc
const got = require('got');
const fs = require("fs");
const Queue = require('better-queue');
const prompts = require('prompts');
const cheerio = require('cheerio');
if (!fs.existsSync("skins")) {
fs.mkdirSync("skins");
}
const instance = got.extend({
headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
},
prefixUrl: 'https://namemc.com',
resolveBodyOnly: true,
throwHttpErrors: false
});
q = new Queue(function (skinURLs, cb) {
skinURLs.forEach(skinURL => {
const skinID = skinURL.replace("/skin/", "");
instance("texture/" + skinID + ".png", { responseType: 'buffer' }).then((skin) => {
fs.writeFile("skins/" + skinID + ".png", skin, (err) => {
if (err) throw err;
cb(null);
});
});
});
}, { batchSize: 5 });
prompts({
type: 'number',
name: 'value',
message: 'A quelle fréquence (par secondes) dois-je récupérer les nouveaux skins?'
}).then((response) => {
console.log("Let's go then!");
setInterval(function () {
instance("minecraft-skins/random").then((HTMLBody) => {
const parseHTML = cheerio.load(HTMLBody);
parseHTML(".card").find("a").each((index, value) => {
const link = parseHTML(value).attr('href');
q.push(link);
});
});
}, response.value * 1000);
setInterval(function () {
const stats = q.getStats();
console.log("J'ai récupéré " + stats.total + " skins!");
}, 30000);
});
{
"name": "get-random-skins",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"better-queue": "^3.8.10",
"cheerio": "^1.0.0-rc.3",
"got": "^11.1.3",
"prompts": "^2.3.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment