mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-12-22 17:23:31 +01:00
add twitter follower count
This commit is contained in:
parent
e6109413aa
commit
8c96f01d70
@ -33,6 +33,9 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu
|
||||
"gitcoin": 1000,
|
||||
"bountiesNetwork": 1000,
|
||||
"total": 1000
|
||||
},
|
||||
"twitter": {
|
||||
"followers": 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
index.js
9
index.js
@ -4,10 +4,12 @@ const { logError } = require('./util/logger')
|
||||
const fetchGitHubRepos = require('./networks/github')
|
||||
const fetchBounties = require('./networks/bounties')
|
||||
const fetchMedium = require('./networks/medium')
|
||||
const fetchTwitter = require('./networks/twitter')
|
||||
|
||||
let cacheGithub = null
|
||||
let cacheBounties = null
|
||||
let cacheMedium = null
|
||||
let cacheTwitter = null
|
||||
|
||||
//
|
||||
// Create the response
|
||||
@ -28,6 +30,10 @@ module.exports = async (req, res) => {
|
||||
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
|
||||
cacheMedium = await fetchMedium()
|
||||
}
|
||||
|
||||
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
|
||||
cacheTwitter = await fetchTwitter()
|
||||
}
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
@ -35,6 +41,7 @@ module.exports = async (req, res) => {
|
||||
res.end(JSON.stringify({
|
||||
github: cacheGithub,
|
||||
bounties: cacheBounties,
|
||||
medium: cacheMedium
|
||||
medium: cacheMedium,
|
||||
twitter: cacheTwitter
|
||||
}))
|
||||
}
|
||||
|
26
networks/twitter.js
Normal file
26
networks/twitter.js
Normal file
@ -0,0 +1,26 @@
|
||||
const fetch = require('node-fetch')
|
||||
const { log, logError } = require('../util/logger')
|
||||
|
||||
const fetchTwitter = async () => {
|
||||
const url = 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol'
|
||||
const start = Date.now()
|
||||
const response = await fetch(url)
|
||||
|
||||
if (response.status !== 200) {
|
||||
logError(`Non-200 response code from Twitter: ${response.status}`)
|
||||
return null
|
||||
}
|
||||
|
||||
const json = await response.json()
|
||||
const followers = json[0].followers_count
|
||||
|
||||
log(
|
||||
`Re-built twitter cache. ` +
|
||||
`Total: ${followers} followers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { followers }
|
||||
}
|
||||
|
||||
module.exports = fetchTwitter
|
Loading…
Reference in New Issue
Block a user