Last active
February 3, 2022 11:51
-
-
Save codeeshop-oc/05dcfdbb165017ea4ddd51fc5669c0c8 to your computer and use it in GitHub Desktop.
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
/* | |
Using https://gist.github.com/paulmillr/4524946#file-github-users-stats-json | |
all -- JSON Data from above Gist to get All Followers | |
Found Least Follow Count | |
*/ | |
let leastFollow = 100000000 | |
all.map(v => { | |
if (v.followers > 0 && v.followers < leastFollow) { | |
leastFollow = v.followers | |
} | |
}) | |
let totalPages = 0 | |
var pages = [] | |
const getResults = page => | |
new Promise(resolve => | |
fetch('https://api.github.com/search/users?q=followers:%3E' + leastFollow + '+sort:followers&per_page=100&page=' + page, { | |
method: 'GET', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
}) | |
.then(res => res.json()) | |
.then(json => { | |
try { | |
pages.push(json.items) | |
if (json.total_count) { | |
totalPages = json.total_count % 100 | |
} | |
} catch (err) { | |
console.log('Error in Page Number: ' + page) | |
console.err(err) | |
} | |
setTimeout(() => resolve(page), 1000) | |
}) | |
); | |
let runFunc = async () => { | |
for (let page = 11; page < totalPages; page++) { | |
await getResults(page) | |
console.log(`Page Fetched: ${page}`); | |
if (pages.length >= totalPages) { | |
break | |
} | |
} | |
} | |
runFunc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment