1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-07-01 06:02:19 +02:00
community-numbers/networks/medium.js

30 lines
805 B
JavaScript
Raw Normal View History

2019-05-14 20:52:48 +02:00
const fetch = require('node-fetch')
2019-06-06 20:26:32 +02:00
const { log, logError } = require('../utils')
2019-05-14 20:52:48 +02:00
const fetchMedium = async () => {
const url = 'https://medium.com/oceanprotocol?format=json'
const start = Date.now()
const response = await fetch(url)
if (response.status !== 200) {
logError(`Non-200 response code from Medium: ${response.status}`)
return null
}
const responseText = await response.text()
const json = await JSON.parse(responseText.replace('])}while(1);</x>', ''))
const { collection } = json.payload
const followers = collection.metadata.followerCount
log(
2019-08-20 11:35:30 +02:00
'Re-built medium cache. ' +
2019-05-14 20:52:48 +02:00
`Total: ${followers} followers. ` +
`Elapsed: ${new Date() - start}ms`
)
return { followers }
}
module.exports = fetchMedium