From 9e4fbfd33e25308bb68822ac172819d11896639f Mon Sep 17 00:00:00 2001 From: TonyCrane Date: Thu, 13 Jul 2023 14:05:51 +0800 Subject: [PATCH 1/2] fix(achievements): update total data acquisition method --- source/plugins/achievements/index.mjs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/plugins/achievements/index.mjs b/source/plugins/achievements/index.mjs index 3a19b15d0fb..3f63851792f 100644 --- a/source/plugins/achievements/index.mjs +++ b/source/plugins/achievements/index.mjs @@ -82,13 +82,16 @@ async function total({imports}) { //Extracting total from github.com/search for (let i = 0; (i < 100) && ((!total.users) || (!total.repositories)); i++) { const page = await browser.newPage() - await page.goto("https://github.com/search") - const result = await page.evaluate(() => [...document.querySelectorAll("h2")].filter(node => /Search more/.test(node.innerText)).shift()?.innerText.trim().match(/(?\d+)M\s+(?repositories|users|issues)$/)?.groups) ?? null - console.debug(`metrics/compute/plugins > achievements > setup found ${result?.type ?? "(?)"}`) - if ((result?.type) && (!total[result.type])) { - const {count, type} = result - total[type] = Number(count) * 10e5 - console.debug(`metrics/compute/plugins > achievements > set total.${type} to ${total[type]}`) + await page.goto("https://github.com/search?q=+created%3A%3E2007") + const totalres = await page.evaluate(() => [...[...document.querySelectorAll("h2")].filter(node => /Filter by/.test(node.innerText)).shift()?.nextSibling?.innerText.trim().matchAll(/(?Repositories|Users|Issues)\n(?.*?)M/g) ?? []]) ?? null + for (const result of totalres) { + const type = result[1]?.toLowerCase() + console.debug(`metrics/compute/plugins > achievements > setup found ${type ?? "(?)"}`) + const count = result[2] ?? "" + if ((count !== "") && (!total[type])) { + total[type] = Number(count) * 10e5 + console.debug(`metrics/compute/plugins > achievements > set total.${type} to ${total[type]}`) + } } await page.close() await imports.wait(10 * Math.random()) From 1a98d92325964385799c406265e8363308395f4e Mon Sep 17 00:00:00 2001 From: TonyCrane Date: Thu, 20 Jul 2023 14:54:44 +0800 Subject: [PATCH 2/2] fix: spelling --- source/plugins/achievements/index.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/plugins/achievements/index.mjs b/source/plugins/achievements/index.mjs index 3f63851792f..25465b32109 100644 --- a/source/plugins/achievements/index.mjs +++ b/source/plugins/achievements/index.mjs @@ -83,8 +83,8 @@ async function total({imports}) { for (let i = 0; (i < 100) && ((!total.users) || (!total.repositories)); i++) { const page = await browser.newPage() await page.goto("https://github.com/search?q=+created%3A%3E2007") - const totalres = await page.evaluate(() => [...[...document.querySelectorAll("h2")].filter(node => /Filter by/.test(node.innerText)).shift()?.nextSibling?.innerText.trim().matchAll(/(?Repositories|Users|Issues)\n(?.*?)M/g) ?? []]) ?? null - for (const result of totalres) { + const results = await page.evaluate(() => [...[...document.querySelectorAll("h2")].filter(node => /Filter by/.test(node.innerText)).shift()?.nextSibling?.innerText.trim().matchAll(/(?Repositories|Users|Issues)\n(?.*?)M/g) ?? []]) ?? null + for (const result of results) { const type = result[1]?.toLowerCase() console.debug(`metrics/compute/plugins > achievements > setup found ${type ?? "(?)"}`) const count = result[2] ?? ""