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

replaced node-fetch with axios

This commit is contained in:
Norbert 2021-11-09 10:36:02 +02:00
parent 3af1f9ee76
commit 9f5dd000dd
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' import { log, logError } from '../utils'
const getGitcoin = async () => { const getGitcoin = async () => {
const response = await fetch( const response = await axios.get(
'https://gitcoin.co/api/v0.1/bounties/?&org=oceanprotocol' 'https://gitcoin.co/api/v0.1/bounties/?&org=oceanprotocol'
) )
@ -11,7 +11,7 @@ const getGitcoin = async () => {
return null return null
} }
const total = await response.json() const total = await response.data
const open = total.filter((item) => item.is_open === true) const open = total.filter((item) => item.is_open === true)
return { total: total.length, open: open.length } return { total: total.length, open: open.length }

View File

@ -1,13 +1,13 @@
import { load } from 'cheerio' import { load } from 'cheerio'
import { log } from '../utils' import { log } from '../utils'
import fetch from 'node-fetch' import axios from 'axios'
export default async function fetchDiscord() { export default async function fetchDiscord() {
const url = 'https://discord.com/invite/TnXjkR5' const url = 'https://discord.com/invite/TnXjkR5'
const start = Date.now() const start = Date.now()
const response = await fetch(url) const response = await axios.get(url)
const body = await response.text() const body = await response.data
const data = await load(body, { normalizeWhitespace: true }) const data = await load(body, { normalizeWhitespace: true })
// extract members count from meta description // 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' import { log, logError, arrSum } from '../utils'
// Request options for all fetch calls // Request options for all fetch calls
@ -17,14 +17,14 @@ export default async function fetchGitHubRepos() {
const url = const url =
'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200' 'https://api.github.com/orgs/oceanprotocol/repos?type=public&per_page=200'
const start = Date.now() const start = Date.now()
const response = await fetch(url, options) const response = await axios.get(url, options)
if (response.status !== 200) { if (response.status !== 200) {
logError(`Non-200 response code from GitHub: ${response.status}`) logError(`Non-200 response code from GitHub: ${response.status}`)
return null return null
} }
const json = await response.json() const json = await response.data
const numbers = json.map((item) => item.stargazers_count) const numbers = json.map((item) => item.stargazers_count)
const stars = arrSum(numbers) const stars = arrSum(numbers)
const repositories = json.length const repositories = json.length

View File

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

View File

@ -1,17 +1,17 @@
import fetch from 'node-fetch' import axios from 'axios'
import { load } from 'cheerio' import { load } from 'cheerio'
import { log, logError } from '../utils' import { log, logError } from '../utils'
export default async function fetchTelegram() { export default async function fetchTelegram() {
const urlCommunity = 'https://t.me/oceanprotocol_community/?pagehidden=false' const urlCommunity = 'https://t.me/oceanprotocol_community/?pagehidden=false'
const start = Date.now() const start = Date.now()
const responseCommunity = await fetch(urlCommunity) const responseCommunity = await axios.get(urlCommunity)
if (responseCommunity.status !== 200) { if (responseCommunity.status !== 200) {
logError(`Non-200 response code from Telegram: ${responseCommunity.status}`) logError(`Non-200 response code from Telegram: ${responseCommunity.status}`)
return null return null
} }
const bodyCommunity = await responseCommunity.text() const bodyCommunity = await responseCommunity.data
const dataCommunity = await load(bodyCommunity, { normalizeWhitespace: true }) const dataCommunity = await load(bodyCommunity, { normalizeWhitespace: true })
let infoCommunity = dataCommunity('.tgme_page_extra').text() 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 urlNews = 'https://t.me/oceanprotocol/?pagehidden=false'
const responseNews = await fetch(urlNews) const responseNews = await axios.get(urlNews)
if (responseNews.status !== 200) { if (responseNews.status !== 200) {
logError(`Non-200 response code from Telegram: ${responseNews.status}`) logError(`Non-200 response code from Telegram: ${responseNews.status}`)
return null return null
} }
const bodyNews = await responseNews.text() const bodyNews = await responseNews.data
const dataNews = await load(bodyNews, { normalizeWhitespace: true }) const dataNews = await load(bodyNews, { normalizeWhitespace: true })
let infoNews = dataNews('.tgme_page_extra').text() 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' import { log, logError } from '../utils'
export default async function fetchTwitter() { export default async function fetchTwitter() {
const url = const url =
'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol' 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=oceanprotocol'
const start = Date.now() const start = Date.now()
const response = await fetch(url) const response = await axios.get(url)
if (response.status !== 200) { if (response.status !== 200) {
logError(`Non-200 response code from Twitter: ${response.status}`) logError(`Non-200 response code from Twitter: ${response.status}`)
return null return null
} }
const json = await response.json() const json = await response.data
const followers = json[0].followers_count const followers = json[0].followers_count
log( log(

18
package-lock.json generated
View File

@ -220,6 +220,14 @@
"integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==",
"dev": true "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": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -1492,6 +1500,11 @@
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
"dev": true "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": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -1925,11 +1938,6 @@
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
"dev": true "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": { "normalize-package-data": {
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", "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 ." "test": "eslint --ignore-path .gitignore --ext .js,.jsx ."
}, },
"dependencies": { "dependencies": {
"axios": "^0.24.0",
"chalk": "^4.1.2", "chalk": "^4.1.2",
"cheerio": "^1.0.0-rc.10", "cheerio": "^1.0.0-rc.10"
"node-fetch": "^2.6.1"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.32.0", "eslint": "^7.32.0",