better ESLINT

Former-commit-id: ff8b138c009cb242c6b2aa76326243401dccc7e1
This commit is contained in:
Ben
2022-02-14 17:10:31 +00:00
parent a6ed6d28e9
commit 43364240ca
11 changed files with 2517 additions and 608 deletions

View File

@@ -14,16 +14,16 @@
const md5 = require('md5');
const fs = require('fs');
fs.readdir('./image/', (err, files) => {
fs.readdir('./image/', (files) => {
files.forEach((file) => {
file = file.split('.png')[0];
const hash = md5(file);
const bucket = hash.substring(0, 4);
const newFile = `./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/${bucket[3]}/${file}.png`;
// if directory doesn't exist, create it
if (!fs.existsSync(`./image/`)) {
fs.mkdirSync(`./image/`);
if (!fs.existsSync('./image/')) {
fs.mkdirSync('./image/');
}
if (!fs.existsSync(`./image/${bucket[0]}/`)) {
fs.mkdirSync(`./image/${bucket[0]}/`);

View File

@@ -13,24 +13,23 @@ async function post(url) {
try {
const res = await axios.get(url, {
method: 'POST',
headers: { 'User-Agent':'Chrome/96.0.4664.175' } ,
headers: { 'User-Agent': 'Chrome/96.0.4664.175' },
});
return res.data.toString();
} catch(e) {
} catch (e) {
fs.appendFileSync('error-set.txt', `${url}\n`);
console.log(`Failed to download ${url}`);
return;
}
}
async function main() {
// sometimes fails on minifigures - doesn't matter though, it's correct enough
const regex = /class=".*?IV_ITEM".*?if \(brickList\["(.*?)"]\).*?nbsp;(.*?) /g
const output = {}
const regex = /class=".*?IV_ITEM".*?if \(brickList\["(.*?)"]\).*?nbsp;(.*?) /g;
const output = {};
for (let i = 0; i < sets.length; i++) {
const set = sets[i];
const data = await post(`https://www.bricklink.com/catalogItemInv.asp?S=${set[2]}`);
output[set[2]] = {};
let pieceCount = 0;
@@ -39,9 +38,9 @@ async function main() {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
pieceCount += parseInt(m[2]);
output[set[2]] = { ...output[set[2]], [m[1]]: parseInt(m[2]) };
output[set[2]] = { ...output[set[2]], [m[1]]: parseInt(m[2]) };
}
console.log(`${i}/${sets.length} ${set[2]} has ${pieceCount} pieces`);