1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-11-16 01:55:17 +01:00
community-numbers/api/networks/discord.js

28 lines
850 B
JavaScript
Raw Normal View History

import puppeteer from 'puppeteer'
import { log } from '../utils'
2020-06-11 15:32:17 +02:00
export default async function fetchDiscord() {
2020-06-11 15:32:17 +02:00
const url = 'https://discord.com/invite/TnXjkR5'
const start = Date.now()
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
await page.goto(url)
const members = await page.evaluate(() => {
// get the activity count element
const membersElement = document.querySelector('[class*="activityCount"] > div:last-child span')
2020-06-16 11:12:27 +02:00
const membersElementText = membersElement.innerText
const number = membersElementText.replace(' Members', '')
return number
})
2020-06-11 15:32:17 +02:00
log(
'Re-fetched Discord. ' +
2020-06-11 15:32:17 +02:00
`Total: ${members} members. ` +
`Elapsed: ${new Date() - start}ms`
)
2020-06-16 11:12:27 +02:00
return { members: Number(members) }
2020-06-11 15:32:17 +02:00
}