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
|