1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-09-28 03:58:40 +02:00
community-numbers/api/networks/twitter.js

26 lines
642 B
JavaScript
Raw Normal View History

2021-11-09 09:36:02 +01:00
import axios from 'axios'
2020-06-16 11:12:27 +02:00
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()
2021-11-09 09:36:02 +01:00
const response = await axios.get(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
2021-11-09 09:36:02 +01:00
const json = await response.data
2020-06-16 12:32:47 +02:00
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
}