Last active
November 12, 2018 10:28
-
-
Save Dafrok/9606370f22f9c81973fac997f4e89834 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
const id = '4199292455301996' | |
let page = 0 | |
async function getUidList() { | |
const result = [] | |
let isEnd = false | |
while (!isEnd) { | |
const response = await fetch(`/api/comments/show?id=${id}&page=${page}`).then(res => res.json()) | |
if (response.data) { | |
const data = response.data.data | |
for (const item of data) { | |
result.push(item.user.id) | |
} | |
page++ | |
} | |
else { | |
return result | |
} | |
} | |
} | |
async sleep(timeout) { | |
return new Promise(resolve => setTimeout(resolve, timeout)) | |
} | |
async function getGenderList(uidList) { | |
const result = [] | |
for (const uid of uidList) { | |
await sleep(500) | |
const response = await fetch(`/api/container/getIndex?containerid=100505${uid}`).then(res => res.json()) | |
result.push(response.data ? response.data.userInfo.gender : '') | |
} | |
return result | |
} | |
async function getData() { | |
const uidList = await getUidList() | |
return await getGenderList(uidList) | |
} | |
getData().then(genderList => { | |
console.log('FEMAL', genderList.filter(g => g === 'f').length) | |
console.log('MALE', genderList.filter(g => g === 'm').length) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment