Merge pull request #84 from oceanprotocol/fix/medium-metrics-not-working

fix medium metrics not working
This commit is contained in:
Norbi 2021-11-09 11:10:49 +02:00 committed by GitHub
commit da4bc4d876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 28 deletions

View File

@ -1,8 +1,8 @@
import fetch from 'node-fetch'
import axios from 'axios'
import { log, logError } from '../utils'
const getGitcoin = async () => {
const response = await fetch(
const response = await axios.get(
'https://gitcoin.co/api/v0.1/bounties/?&org=oceanprotocol'
)
@ -11,7 +11,7 @@ const getGitcoin = async () => {
return null
}
const total = await response.json()
const total = response.data
const open = total.filter((item) => item.is_open === true)
return { total: total.length, open: open.length }

View File

@ -1,13 +1,13 @@
import { load } from 'cheerio'
import { log } from '../utils'
import fetch from 'node-fetch'
import axios from 'axios'
export default async function fetchDiscord() {
const url = 'https://discord.com/invite/TnXjkR5'
const start = Date.now()
const response = await fetch(url)
const body = await response.text()
const response = await axios.get(url)
const body = response.data
const data = await load(body, { normalizeWhitespace: true })
// extract members count from meta description

View File

@ -1,4 +1,4 @@
import fetch from 'node-fetch'
import axios from 'axios'
import { log, logError, arrSum } from '../utils'
// Request options for all fetch calls
@ -17,14 +17,14 @@ 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 response = await axios.get(url, options)
if (response.status !== 200) {
logError(`Non-200 response code from GitHub: ${response.status}`)
return null
}
const json = await response.json()
const json = response.data
const numbers = json.map((item) => item.stargazers_count)
const stars = arrSum(numbers)
const repositories = json.length

View File

@ -1,17 +1,17 @@
import fetch from 'node-fetch'
import axios from 'axios'
import { log, logError } from '../utils'
export default async function fetchMedium() {
const url = 'https://medium.com/oceanprotocol?format=json'
const url = 'http://medium.com/oceanprotocol?format=json'
const start = Date.now()
const response = await fetch(url)
const response = await axios.get(url)
if (response.status !== 200) {
logError(`Non-200 response code from Medium: ${response.status}`)
return null
}
const responseText = await response.text()
const responseText = response.data
const json = await JSON.parse(responseText.replace('])}while(1);</x>', ''))
const { collection } = json.payload

View File

@ -1,17 +1,17 @@
import fetch from 'node-fetch'
import axios from 'axios'
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 responseCommunity = await axios.get(urlCommunity)
if (responseCommunity.status !== 200) {
logError(`Non-200 response code from Telegram: ${responseCommunity.status}`)
return null
}
const bodyCommunity = await responseCommunity.text()
const bodyCommunity = await responseCommunity.data
const dataCommunity = await load(bodyCommunity, { normalizeWhitespace: true })
let infoCommunity = dataCommunity('.tgme_page_extra').text()
@ -28,13 +28,13 @@ export default async function fetchTelegram() {
)
const urlNews = 'https://t.me/oceanprotocol/?pagehidden=false'
const responseNews = await fetch(urlNews)
const responseNews = await axios.get(urlNews)
if (responseNews.status !== 200) {
logError(`Non-200 response code from Telegram: ${responseNews.status}`)
return null
}
const bodyNews = await responseNews.text()
const bodyNews = await responseNews.data
const dataNews = await load(bodyNews, { normalizeWhitespace: true })
let infoNews = dataNews('.tgme_page_extra').text()

View File

@ -1,18 +1,18 @@
import fetch from 'node-fetch'
import axios from 'axios'
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 response = await axios.get(url)
if (response.status !== 200) {
logError(`Non-200 response code from Twitter: ${response.status}`)
return null
}
const json = await response.json()
const json = response.data
const followers = json[0].followers_count
log(

18
package-lock.json generated
View File

@ -220,6 +220,14 @@
"integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==",
"dev": true
},
"axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"requires": {
"follow-redirects": "^1.14.4"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -1492,6 +1500,11 @@
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
"dev": true
},
"follow-redirects": {
"version": "1.14.5",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz",
"integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA=="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -1925,11 +1938,6 @@
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
"dev": true
},
"node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"normalize-package-data": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",

View File

@ -7,9 +7,9 @@
"test": "eslint --ignore-path .gitignore --ext .js,.jsx ."
},
"dependencies": {
"axios": "^0.24.0",
"chalk": "^4.1.2",
"cheerio": "^1.0.0-rc.10",
"node-fetch": "^2.6.1"
"cheerio": "^1.0.0-rc.10"
},
"devDependencies": {
"eslint": "^7.32.0",