mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-11-24 02:55:41 +01:00
fixes & formatting
This commit is contained in:
parent
a9bf257d71
commit
bf53963fe0
@ -1,13 +0,0 @@
|
||||
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.json]
|
||||
indent_size = 2
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"extends": "oceanprotocol"
|
||||
"extends": ["oceanprotocol", "prettier"]
|
||||
}
|
||||
|
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
@ -1,8 +1,8 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: '03:00'
|
||||
timezone: Europe/Berlin
|
||||
- package-ecosystem: npm
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: daily
|
||||
time: '03:00'
|
||||
timezone: Europe/Berlin
|
||||
|
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"tabWidth": 2
|
||||
}
|
@ -2,4 +2,4 @@ language: node_js
|
||||
node_js: node
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
email: false
|
||||
|
42
README.md
42
README.md
@ -21,27 +21,27 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu
|
||||
|
||||
```json
|
||||
{
|
||||
"github": {
|
||||
"stars": 1000,
|
||||
"repos": 1000
|
||||
},
|
||||
"medium": {
|
||||
"followers": 1000
|
||||
},
|
||||
"bounties": {
|
||||
"open": 1000,
|
||||
"total": 1000
|
||||
},
|
||||
"twitter": {
|
||||
"followers": 1000
|
||||
},
|
||||
"telegram": {
|
||||
"community": 1000,
|
||||
"news": 1000
|
||||
},
|
||||
"discord": {
|
||||
"members": 1000
|
||||
}
|
||||
"github": {
|
||||
"stars": 1000,
|
||||
"repos": 1000
|
||||
},
|
||||
"medium": {
|
||||
"followers": 1000
|
||||
},
|
||||
"bounties": {
|
||||
"open": 1000,
|
||||
"total": 1000
|
||||
},
|
||||
"twitter": {
|
||||
"followers": 1000
|
||||
},
|
||||
"telegram": {
|
||||
"community": 1000,
|
||||
"news": 1000
|
||||
},
|
||||
"discord": {
|
||||
"members": 1000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
84
api/index.js
84
api/index.js
@ -11,54 +11,54 @@ import fetchDiscord from './networks/discord'
|
||||
// Create the response
|
||||
//
|
||||
export default async (req, res) => {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET')
|
||||
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET')
|
||||
|
||||
let response = {}
|
||||
let response = {}
|
||||
|
||||
try {
|
||||
const github = await fetchGitHubRepos()
|
||||
response = { ...response, github }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const github = await fetchGitHubRepos()
|
||||
response = { ...response, github }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
try {
|
||||
const bounties = await fetchBounties()
|
||||
response = { ...response, bounties }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const bounties = await fetchBounties()
|
||||
response = { ...response, bounties }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
try {
|
||||
const medium = await fetchMedium()
|
||||
response = { ...response, medium }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const medium = await fetchMedium()
|
||||
response = { ...response, medium }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
try {
|
||||
const twitter = await fetchTwitter()
|
||||
response = { ...response, twitter }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const twitter = await fetchTwitter()
|
||||
response = { ...response, twitter }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
try {
|
||||
const telegram = await fetchTelegram()
|
||||
response = { ...response, telegram }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const telegram = await fetchTelegram()
|
||||
response = { ...response, telegram }
|
||||
} catch (error) {
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
try {
|
||||
const discord = await fetchDiscord()
|
||||
response = { ...response, discord }
|
||||
} catch (error) {
|
||||
// fake fallback response cause puppeteer fails a lot
|
||||
response = { ...response, discord: { members: '240' } }
|
||||
logError(error.message)
|
||||
}
|
||||
try {
|
||||
const discord = await fetchDiscord()
|
||||
response = { ...response, discord }
|
||||
} catch (error) {
|
||||
// fake fallback response cause puppeteer fails a lot
|
||||
response = { ...response, discord: { members: '240' } }
|
||||
logError(error.message)
|
||||
}
|
||||
|
||||
res.json(response)
|
||||
res.json(response)
|
||||
}
|
||||
|
@ -2,28 +2,30 @@ import fetch from 'node-fetch'
|
||||
import { log, logError } from '../utils'
|
||||
|
||||
const getGitcoin = async () => {
|
||||
const response = await fetch('https://gitcoin.co/api/v0.1/bounties/?&org=oceanprotocol')
|
||||
const response = await fetch(
|
||||
'https://gitcoin.co/api/v0.1/bounties/?&org=oceanprotocol'
|
||||
)
|
||||
|
||||
if (response.status !== 200) {
|
||||
logError(`Non-200 response code from Gitcoin: ${response.status}`)
|
||||
return null
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
logError(`Non-200 response code from Gitcoin: ${response.status}`)
|
||||
return null
|
||||
}
|
||||
|
||||
const total = await response.json()
|
||||
const open = total.filter((item) => item.is_open === true)
|
||||
const total = await response.json()
|
||||
const open = total.filter((item) => item.is_open === true)
|
||||
|
||||
return { total: total.length, open: open.length }
|
||||
return { total: total.length, open: open.length }
|
||||
}
|
||||
|
||||
export default async function fetchBounties() {
|
||||
const start = Date.now()
|
||||
const { total, open } = await getGitcoin()
|
||||
const start = Date.now()
|
||||
const { total, open } = await getGitcoin()
|
||||
|
||||
log(
|
||||
'Re-fetched bounties. ' +
|
||||
`Total: ${total} bounties. Open: ${open} bounties. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
log(
|
||||
'Re-fetched bounties. ' +
|
||||
`Total: ${total} bounties. Open: ${open} bounties. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { open, total }
|
||||
return { open, total }
|
||||
}
|
||||
|
@ -2,26 +2,28 @@ import puppeteer from 'puppeteer'
|
||||
import { log } from '../utils'
|
||||
|
||||
export default async function fetchDiscord() {
|
||||
const url = 'https://discord.com/invite/TnXjkR5'
|
||||
const start = Date.now()
|
||||
const url = 'https://discord.com/invite/TnXjkR5'
|
||||
const start = Date.now()
|
||||
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
await page.goto(url)
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
await page.goto(url)
|
||||
|
||||
const members = await page.evaluate(() => {
|
||||
// get the activity count element
|
||||
const membersElement = document.querySelector('[class*="activityCount"] > div:last-child span')
|
||||
const membersElementText = membersElement.innerText
|
||||
const number = membersElementText.replace(' Members', '')
|
||||
return number
|
||||
})
|
||||
|
||||
log(
|
||||
'Re-fetched Discord. ' +
|
||||
`Total: ${members} members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
const members = await page.evaluate(() => {
|
||||
// get the activity count element
|
||||
const membersElement = document.querySelector(
|
||||
'[class*="activityCount"] > div:last-child span'
|
||||
)
|
||||
const membersElementText = membersElement.innerText
|
||||
const number = membersElementText.replace(' Members', '')
|
||||
return number
|
||||
})
|
||||
|
||||
return { members: Number(members) }
|
||||
log(
|
||||
'Re-fetched Discord. ' +
|
||||
`Total: ${members} members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { members: Number(members) }
|
||||
}
|
||||
|
@ -3,45 +3,46 @@ import { log, logError, arrSum } from '../utils'
|
||||
|
||||
// Request options for all fetch calls
|
||||
const options = {
|
||||
headers: {
|
||||
// For getting topics, see note on https://developer.github.com/v3/search/
|
||||
// Accept: 'application/vnd.github.mercy-preview+json'
|
||||
Accept: 'application/vnd.github.preview'
|
||||
}
|
||||
headers: {
|
||||
// For getting topics, see note on https://developer.github.com/v3/search/
|
||||
// Accept: 'application/vnd.github.mercy-preview+json'
|
||||
Accept: 'application/vnd.github.preview'
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Fetch all public GitHub repos
|
||||
//
|
||||
export default async function fetchGitHubRepos() {
|
||||
const url = 'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200'
|
||||
const start = Date.now()
|
||||
const response = await fetch(url, options)
|
||||
const url =
|
||||
'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200'
|
||||
const start = Date.now()
|
||||
const response = await fetch(url, options)
|
||||
|
||||
if (response.status !== 200) {
|
||||
logError(`Non-200 response code from GitHub: ${response.status}`)
|
||||
return null
|
||||
if (response.status !== 200) {
|
||||
logError(`Non-200 response code from GitHub: ${response.status}`)
|
||||
return null
|
||||
}
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
const numbers = []
|
||||
|
||||
json.map((item) => {
|
||||
if (item.stargazers_count) {
|
||||
return numbers.push(item.stargazers_count)
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const json = await response.json()
|
||||
const stars = arrSum(numbers)
|
||||
const repositories = json.length
|
||||
|
||||
const numbers = []
|
||||
log(
|
||||
'Re-fetched GitHub. ' +
|
||||
`Total: ${repositories} public projects with a total of ${stars} stargazers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
json.map(item => {
|
||||
if (item.stargazers_count) {
|
||||
return numbers.push(item.stargazers_count)
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const stars = arrSum(numbers)
|
||||
const repositories = json.length
|
||||
|
||||
log(
|
||||
'Re-fetched GitHub. ' +
|
||||
`Total: ${repositories} public projects with a total of ${stars} stargazers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { stars, repositories }
|
||||
return { stars, repositories }
|
||||
}
|
||||
|
@ -2,26 +2,26 @@ 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)
|
||||
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
|
||||
}
|
||||
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 responseText = await response.text()
|
||||
const json = await JSON.parse(responseText.replace('])}while(1);</x>', ''))
|
||||
const { collection } = json.payload
|
||||
|
||||
const followers = collection.metadata.followerCount
|
||||
const followers = collection.metadata.followerCount
|
||||
|
||||
log(
|
||||
'Re-fetched Medium. ' +
|
||||
`Total: ${followers} followers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
log(
|
||||
'Re-fetched Medium. ' +
|
||||
`Total: ${followers} followers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { followers }
|
||||
return { followers }
|
||||
}
|
||||
|
@ -3,46 +3,49 @@ import { load } from 'cheerio'
|
||||
import { log, logError } from '../utils'
|
||||
|
||||
export default async function fetchTelegram() {
|
||||
const urlCommunity = 'https://t.me/oceanprotocol_community/?pagehidden=false'
|
||||
const start = Date.now()
|
||||
const responseCommunity = await fetch(urlCommunity)
|
||||
const urlCommunity = 'https://t.me/oceanprotocol_community/?pagehidden=false'
|
||||
const start = Date.now()
|
||||
const responseCommunity = await fetch(urlCommunity)
|
||||
|
||||
if (responseCommunity.status !== 200) {
|
||||
logError(`Non-200 response code from Telegram: ${responseCommunity.status}`)
|
||||
return null
|
||||
}
|
||||
const bodyCommunity = await responseCommunity.text()
|
||||
const dataCommunity = await load(bodyCommunity, { normalizeWhitespace: true })
|
||||
if (responseCommunity.status !== 200) {
|
||||
logError(`Non-200 response code from Telegram: ${responseCommunity.status}`)
|
||||
return null
|
||||
}
|
||||
const bodyCommunity = await responseCommunity.text()
|
||||
const dataCommunity = await load(bodyCommunity, { normalizeWhitespace: true })
|
||||
|
||||
let infoCommunity = dataCommunity('.tgme_page_extra').text()
|
||||
infoCommunity = infoCommunity.replace(' members', '').replace(' ', '').replace(' ', '')
|
||||
const membersCommunity = parseInt(infoCommunity)
|
||||
let infoCommunity = dataCommunity('.tgme_page_extra').text()
|
||||
infoCommunity = infoCommunity
|
||||
.replace(' members', '')
|
||||
.replace(' ', '')
|
||||
.replace(' ', '')
|
||||
const membersCommunity = parseInt(infoCommunity)
|
||||
|
||||
log(
|
||||
'Re-fetched Telegram. ' +
|
||||
`Total: ${membersCommunity} oceanprotocol_community members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
log(
|
||||
'Re-fetched Telegram. ' +
|
||||
`Total: ${membersCommunity} oceanprotocol_community members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
const urlNews = 'https://t.me/oceanprotocol/?pagehidden=false'
|
||||
const responseNews = await fetch(urlNews)
|
||||
const urlNews = 'https://t.me/oceanprotocol/?pagehidden=false'
|
||||
const responseNews = await fetch(urlNews)
|
||||
|
||||
if (responseNews.status !== 200) {
|
||||
logError(`Non-200 response code from Telegram: ${responseNews.status}`)
|
||||
return null
|
||||
}
|
||||
const bodyNews = await responseNews.text()
|
||||
const dataNews = await load(bodyNews, { normalizeWhitespace: true })
|
||||
if (responseNews.status !== 200) {
|
||||
logError(`Non-200 response code from Telegram: ${responseNews.status}`)
|
||||
return null
|
||||
}
|
||||
const bodyNews = await responseNews.text()
|
||||
const dataNews = await load(bodyNews, { normalizeWhitespace: true })
|
||||
|
||||
let infoNews = dataNews('.tgme_page_extra').text()
|
||||
infoNews = infoNews.replace(' members', '').replace(' ', '').replace(' ', '')
|
||||
const membersNews = parseInt(infoNews)
|
||||
let infoNews = dataNews('.tgme_page_extra').text()
|
||||
infoNews = infoNews.replace(' members', '').replace(' ', '').replace(' ', '')
|
||||
const membersNews = parseInt(infoNews)
|
||||
|
||||
log(
|
||||
'Re-fetched Telegram. ' +
|
||||
`Total: ${membersCommunity} oceanprotocol members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
log(
|
||||
'Re-fetched Telegram. ' +
|
||||
`Total: ${membersCommunity} oceanprotocol members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { community: membersCommunity, news: membersNews }
|
||||
return { community: membersCommunity, news: membersNews }
|
||||
}
|
||||
|
@ -2,23 +2,24 @@ import fetch from 'node-fetch'
|
||||
import { log, logError } from '../utils'
|
||||
|
||||
export default async function fetchTwitter() {
|
||||
const url = 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol'
|
||||
const start = Date.now()
|
||||
const response = await fetch(url)
|
||||
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
|
||||
}
|
||||
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
|
||||
const json = await response.json()
|
||||
const followers = json[0].followers_count
|
||||
|
||||
log(
|
||||
'Re-fetched Twitter. ' +
|
||||
`Total: ${followers} followers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
log(
|
||||
'Re-fetched Twitter. ' +
|
||||
`Total: ${followers} followers. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { followers }
|
||||
return { followers }
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* eslint-disable no-console */
|
||||
const chalk = require('chalk')
|
||||
|
||||
const log = text => console.log(text)
|
||||
const logError = text => console.error(chalk.bold.red(text))
|
||||
const log = (text) => console.log(text)
|
||||
const logError = (text) => console.error(chalk.bold.red(text))
|
||||
|
||||
const arrSum = arr => arr.reduce((a, b) => a + b, 0)
|
||||
const arrSum = (arr) => arr.reduce((a, b) => a + b, 0)
|
||||
|
||||
module.exports = { log, logError, arrSum }
|
||||
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -757,6 +757,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"eslint-config-prettier": {
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz",
|
||||
"integrity": "sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"get-stdin": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"eslint-config-standard": {
|
||||
"version": "14.0.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-14.0.0.tgz",
|
||||
@ -1186,6 +1195,12 @@
|
||||
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
||||
"dev": true
|
||||
},
|
||||
"get-stdin": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz",
|
||||
"integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==",
|
||||
"dev": true
|
||||
},
|
||||
"get-stream": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
|
||||
|
@ -9,13 +9,13 @@
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0",
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
"ms": "^2.1.1",
|
||||
"node-fetch": "^2.6.0",
|
||||
"puppeteer": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.2.0",
|
||||
"eslint-config-oceanprotocol": "^1.5.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-plugin-node": "^11.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
{
|
||||
"routes": [
|
||||
{ "src": "/", "dest": "/api" }
|
||||
]
|
||||
"routes": [{ "src": "/", "dest": "/api" }]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user