1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-11-25 11:28:45 +01:00
community-numbers/api/networks/twitter.js

26 lines
645 B
JavaScript
Raw Normal View History

2020-06-16 11:12:27 +02:00
import fetch from 'node-fetch'
import { log, logError } from '../utils'
2019-05-14 20:59:15 +02:00
2020-06-16 11:12:27 +02:00
export default async function fetchTwitter() {
2020-06-16 12:32:47 +02:00
const url =
'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol'
const start = Date.now()
const response = await fetch(url)
2019-05-14 20:59:15 +02:00
2020-06-16 12:32:47 +02:00
if (response.status !== 200) {
logError(`Non-200 response code from Twitter: ${response.status}`)
return null
}
2019-05-14 20:59:15 +02:00
2020-06-16 12:32:47 +02:00
const json = await response.json()
const followers = json[0].followers_count
2019-05-14 20:59:15 +02:00
2020-06-16 12:32:47 +02:00
log(
2020-06-16 15:16:31 +02:00
'✓ Twitter. ' +
2020-06-16 12:32:47 +02:00
`Total: ${followers} followers. ` +
`Elapsed: ${new Date() - start}ms`
)
2019-05-14 20:59:15 +02:00
2020-06-16 12:32:47 +02:00
return { followers }
2019-05-14 20:59:15 +02:00
}