mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-12-23 01:29:49 +01:00
27 lines
717 B
JavaScript
27 lines
717 B
JavaScript
const fetch = require('node-fetch')
|
|
const { log, logError } = require('../utils')
|
|
|
|
const fetchTwitter = async () => {
|
|
const url = 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol'
|
|
const start = Date.now()
|
|
const response = await fetch(url)
|
|
|
|
if (response.status !== 200) {
|
|
logError(`Non-200 response code from Twitter: ${response.status}`)
|
|
return null
|
|
}
|
|
|
|
const json = await response.json()
|
|
const followers = json[0].followers_count
|
|
|
|
log(
|
|
`Re-built twitter cache. ` +
|
|
`Total: ${followers} followers. ` +
|
|
`Elapsed: ${new Date() - start}ms`
|
|
)
|
|
|
|
return { followers }
|
|
}
|
|
|
|
module.exports = fetchTwitter
|