Skip to content

Instantly share code, notes, and snippets.

@Dafrok
Last active November 12, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dafrok/9606370f22f9c81973fac997f4e89834 to your computer and use it in GitHub Desktop.
Save Dafrok/9606370f22f9c81973fac997f4e89834 to your computer and use it in GitHub Desktop.
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