Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up wiki scraping #42

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"clear-output": "rm -rf ./output/",
"wiki-check-changed": "tsx ./src/cli-change-checker.ts",
"scrape-wiki": "tsx ./src/cli-scraper.ts --output ./output/ --customOverrides ./custom/",
"scrape-wiki": "tsx ./src/cli-scraper.ts --output ./output/ --customOverrides ./custom/ --wipe",
"pack-release": "tsx ./src/cli-release-packer.ts --input ./output/ --output ./dist/release/",
"publish-library": "tsx ./src/cli-library-publisher.ts --input ./output/ --output ./dist/libraries/garrysmod",
"stylua-custom": "npx --yes @johnnymorganz/[email protected] ./custom",
Expand Down
9 changes: 8 additions & 1 deletion src/cli-scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async function startScrape() {

const pageIndexes = await scrapeAndCollect(pageListScraper);

let queue: Promise<any>[] = [];
for (const pageIndex of pageIndexes) {
const pageMarkupScraper = new WikiPageMarkupScraper(`${baseUrl}/${pageIndex.address}?format=text`);

Expand Down Expand Up @@ -119,7 +120,13 @@ async function startScrape() {
fs.writeFileSync(path.join(baseDirectory, moduleName, `${fileName}.json`), json);
});

await pageMarkupScraper.scrape();
queue.push(pageMarkupScraper.scrape());

if (queue.length > 20)
{
await Promise.allSettled(queue);
queue = [];
}
}

console.log(`Done with scraping! You can find the output in ${baseDirectory}`);
Expand Down
Loading