Files
legolog/db/mostpopularbricks.js
Ben f229fe05f3 redid database
Former-commit-id: 93d6c70302791c97062cefa6ab9938739049468c
2022-04-10 22:31:33 +01:00

36 lines
1007 B
JavaScript

// get all the id's from this page
// https://brickarchitect.com/most-common-lego-parts/
const fs = require('fs');
const axios = require('axios');
async function get(url) {
// axios return HTML from website
try {
const res = await axios.get(url, {
method: 'GET',
headers: { 'User-Agent': 'Chrome/96.0.4664.175' },
});
return res.data.toString();
} catch (e) {
fs.appendFileSync('error-set.txt', `${url}\n`);
console.log(`Failed to download ${url}`);
}
}
async function main() {
const regex = /https:\/\/brickarchitect\.com\/content\/parts\/(.*?)\.png/g;
const data = await get('https://brickarchitect.com/most-common-lego-parts/');
data.match(regex).forEach((element) => {
// get out the id
const id = element.split('/')[5].split('.')[0];
console.log(id);
fs.appendFileSync('db/res/most-common-lego-parts.txt', `${id}\n`);
});
}
main();