mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-12-22 17:23:31 +01:00
28 lines
847 B
JavaScript
28 lines
847 B
JavaScript
import { load } from 'cheerio'
|
|
import { log } from '../utils'
|
|
import axios from 'axios'
|
|
|
|
export default async function fetchDiscord() {
|
|
const url = 'https://discord.com/invite/TnXjkR5'
|
|
const start = Date.now()
|
|
|
|
const response = await axios.get(url)
|
|
const body = response.data
|
|
const data = await load(body, { normalizeWhitespace: true })
|
|
|
|
// extract members count from meta description
|
|
const metaDescription = data('meta[name="description"]').attr('content')
|
|
const regex = /\d+[,]\d+/ // one or more digits separated by comma
|
|
const number = metaDescription.match(regex)
|
|
const membersNumber = number[0].replace(/,/,'') // eliminate comma from number
|
|
const members = parseInt(membersNumber)
|
|
|
|
log(
|
|
'✓ Discord. ' +
|
|
`Total: ${members} members. ` +
|
|
`Elapsed: ${new Date() - start}ms`
|
|
)
|
|
|
|
return { members }
|
|
}
|