Last active
January 30, 2024 22:47
-
-
Save kimjisub/0641a04d5d6d8991f6e9e2a4fdd616d6 to your computer and use it in GitHub Desktop.
Github Contributes Crawler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
githubUsernames = ['Anas-wg', 'CHEDDA-L', 'CosmicSandBox', 'Dawon00', 'ElvaCJ', 'GNAchoux', 'HSK021843', 'HwangBBang', 'Jeonhui', 'KeyWaveTree', 'LYZAcell', 'MillionKiwi', 'ParkWonjeong', 'ParkYujin1029', 'SR-Kwon', 'SeEunJeon', 'Seoulmycat', 'ShinHyeongcheol', 'Sunhwak', 'YangEonPil', 'Yeeun411', 'anhyeryeon2', 'bewheneverwhatiwant', 'bome24', 'daehyuh', 'dori108', 'g00hyun', 'gomsang', 'hwarange', 'ijeongm', 'jaeiko', 'jiHeeFlee', 'juhui88', 'kimjisub', 'koojun99', 'leestana01', 'ohprettyhak', 'ryudonghyun123', 's00ngle', 'seojin-yoon', 'sese2204', 'soeun0127', 'sooo03', 'soyan22', 'whitetor', 'yanghyen', 'yideniyi', 'yiseoffline', 'younkyum', 'yunejae12'] | |
async function getCommitCountHtml(username) { | |
try { | |
const profileResponse = await fetch(`https://github.com/${username}`); | |
const profileHtml = await profileResponse.text(); | |
const parser = new DOMParser(); | |
const profileDoc = parser.parseFromString(profileHtml, "text/html"); | |
const contributionsElem = profileDoc.querySelector("div.js-yearly-contributions h2"); | |
if (contributionsElem) { | |
const contributionsText = contributionsElem.textContent.trim(); | |
const contributionsMatch = contributionsText.match(/(\d[\d,]*)\s+contributions?/); | |
if (contributionsMatch) { | |
const totalCommits = parseInt(contributionsMatch[1].replace(/,/g, ''), 10); | |
return { | |
username, | |
totalCommits | |
}; | |
} | |
} | |
throw new Error("Could not find contributions element"); | |
} catch (error) { | |
console.error("Error:", error.message); | |
return { | |
username, | |
totalCommits: -1 | |
}; | |
} | |
} | |
delay = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms)); | |
async function fetchCommitCounts(usernames) { | |
const results = []; | |
for (const username of usernames) { | |
const result = await getCommitCountHtml(username); | |
console.log(result.username, result.totalCommits) | |
results.push(result) | |
await delay(50); | |
} | |
return results.sort((a,b)=>(b.totalCommits - a.totalCommits)); | |
} | |
res = await fetchCommitCounts(githubUsernames) | |
console.log(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment