1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-12-23 01:29:49 +01:00

add twitter follower count

This commit is contained in:
Matthias Kretschmann 2019-05-14 20:59:15 +02:00
parent e6109413aa
commit 8c96f01d70
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 37 additions and 1 deletions

View File

@ -33,6 +33,9 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu
"gitcoin": 1000, "gitcoin": 1000,
"bountiesNetwork": 1000, "bountiesNetwork": 1000,
"total": 1000 "total": 1000
},
"twitter": {
"followers": 1000
} }
} }
} }

View File

@ -4,10 +4,12 @@ const { logError } = require('./util/logger')
const fetchGitHubRepos = require('./networks/github') const fetchGitHubRepos = require('./networks/github')
const fetchBounties = require('./networks/bounties') const fetchBounties = require('./networks/bounties')
const fetchMedium = require('./networks/medium') const fetchMedium = require('./networks/medium')
const fetchTwitter = require('./networks/twitter')
let cacheGithub = null let cacheGithub = null
let cacheBounties = null let cacheBounties = null
let cacheMedium = null let cacheMedium = null
let cacheTwitter = null
// //
// Create the response // Create the response
@ -28,6 +30,10 @@ module.exports = async (req, res) => {
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) { if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
cacheMedium = await fetchMedium() cacheMedium = await fetchMedium()
} }
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
cacheTwitter = await fetchTwitter()
}
} catch (error) { } catch (error) {
logError(error.message) logError(error.message)
} }
@ -35,6 +41,7 @@ module.exports = async (req, res) => {
res.end(JSON.stringify({ res.end(JSON.stringify({
github: cacheGithub, github: cacheGithub,
bounties: cacheBounties, bounties: cacheBounties,
medium: cacheMedium medium: cacheMedium,
twitter: cacheTwitter
})) }))
} }

26
networks/twitter.js Normal file
View 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