mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-11-25 11:28:45 +01:00
30 lines
805 B
JavaScript
30 lines
805 B
JavaScript
const fetch = require('node-fetch')
|
|
const { log, logError } = require('../utils')
|
|
|
|
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(
|
|
`Re-built medium cache. ` +
|
|
`Total: ${followers} followers. ` +
|
|
`Elapsed: ${new Date() - start}ms`
|
|
)
|
|
|
|
return { followers }
|
|
}
|
|
|
|
module.exports = fetchMedium
|