Skip to content

Commit

Permalink
fix(achievements): update total data acquisition method (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCrane authored Jul 24, 2023
1 parent f6c4f63 commit 8bf2772
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions source/plugins/achievements/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<count>\d+)M\s+(?<type>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 results = await page.evaluate(() => [...[...document.querySelectorAll("h2")].filter(node => /Filter by/.test(node.innerText)).shift()?.nextSibling?.innerText.trim().matchAll(/(?<type>Repositories|Users|Issues)\n(?<count>.*?)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] ?? ""
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())
Expand Down

0 comments on commit 8bf2772

Please sign in to comment.