mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-11-16 01:55:17 +01:00
28 lines
726 B
JavaScript
28 lines
726 B
JavaScript
import fetch from 'node-fetch'
|
|
import { log, logError } from '../utils'
|
|
|
|
export default async function fetchMedium() {
|
|
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(
|
|
'✓ Medium. ' +
|
|
`Total: ${followers} followers. ` +
|
|
`Elapsed: ${new Date() - start}ms`
|
|
)
|
|
|
|
return { followers }
|
|
}
|