2020-06-16 16:14:31 +02:00
|
|
|
import { load } from 'cheerio'
|
2020-06-16 10:48:36 +02:00
|
|
|
import { log } from '../utils'
|
2020-06-16 16:14:31 +02:00
|
|
|
import fetch from 'node-fetch'
|
2020-06-16 15:16:31 +02:00
|
|
|
|
2020-06-16 10:48:36 +02:00
|
|
|
export default async function fetchDiscord() {
|
2020-06-16 12:32:47 +02:00
|
|
|
const url = 'https://discord.com/invite/TnXjkR5'
|
|
|
|
const start = Date.now()
|
2020-06-11 15:32:17 +02:00
|
|
|
|
2020-06-16 16:14:31 +02:00
|
|
|
const response = await fetch(url)
|
|
|
|
const body = await response.text()
|
|
|
|
const data = await load(body, { normalizeWhitespace: true })
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 16:14:31 +02:00
|
|
|
// extract members count from meta description
|
|
|
|
const metaDescription = data('meta[name="description"]').attr('content')
|
2021-02-04 12:15:41 +01:00
|
|
|
const regex = /\d+[,]\d+/ // one or more digits separated by comma
|
2020-06-16 16:14:31 +02:00
|
|
|
const number = metaDescription.match(regex)
|
2021-02-04 12:15:41 +01:00
|
|
|
const membersNumber = number[0].replace(/,/,'') // eliminate comma from number
|
2021-02-04 12:11:07 +01:00
|
|
|
const members = parseInt(membersNumber)
|
2020-06-16 12:32:47 +02:00
|
|
|
|
|
|
|
log(
|
2020-06-16 15:16:31 +02:00
|
|
|
'✓ Discord. ' +
|
2020-06-16 12:32:47 +02:00
|
|
|
`Total: ${members} members. ` +
|
|
|
|
`Elapsed: ${new Date() - start}ms`
|
|
|
|
)
|
2020-06-11 15:32:17 +02:00
|
|
|
|
2020-06-16 15:35:28 +02:00
|
|
|
return { members }
|
2020-06-11 15:32:17 +02:00
|
|
|
}
|