1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-11-28 23:06:22 +01:00
community-numbers/api/networks/discord.js

27 lines
746 B
JavaScript

import { load } from 'cheerio'
import { log } from '../utils'
import fetch from 'node-fetch'
export default async function fetchDiscord() {
const url = 'https://discord.com/invite/TnXjkR5'
const start = Date.now()
const response = await fetch(url)
const body = await response.text()
const data = await load(body, { normalizeWhitespace: true })
// extract members count from meta description
const metaDescription = data('meta[name="description"]').attr('content')
const regex = /\d+/ // one or more digits
const number = metaDescription.match(regex)
const members = parseInt(number[0])
log(
'✓ Discord. ' +
`Total: ${members} members. ` +
`Elapsed: ${new Date() - start}ms`
)
return { members }
}