From 9f5dd000dd758c1471c040e7cbc3cba9bed99c21 Mon Sep 17 00:00:00 2001 From: Norbert Date: Tue, 9 Nov 2021 10:36:02 +0200 Subject: [PATCH] replaced node-fetch with axios --- api/networks/bounties.js | 6 +++--- api/networks/discord.js | 6 +++--- api/networks/github.js | 6 +++--- api/networks/medium.js | 8 ++++---- api/networks/telegram.js | 10 +++++----- api/networks/twitter.js | 6 +++--- package-lock.json | 18 +++++++++++++----- package.json | 4 ++-- 8 files changed, 36 insertions(+), 28 deletions(-) diff --git a/api/networks/bounties.js b/api/networks/bounties.js index 3f4c370..d389bbc 100644 --- a/api/networks/bounties.js +++ b/api/networks/bounties.js @@ -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 = await response.data const open = total.filter((item) => item.is_open === true) return { total: total.length, open: open.length } diff --git a/api/networks/discord.js b/api/networks/discord.js index 49f5f7b..80a8c21 100644 --- a/api/networks/discord.js +++ b/api/networks/discord.js @@ -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 = await response.data const data = await load(body, { normalizeWhitespace: true }) // extract members count from meta description diff --git a/api/networks/github.js b/api/networks/github.js index 9d79249..c6a3416 100755 --- a/api/networks/github.js +++ b/api/networks/github.js @@ -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 = await response.data const numbers = json.map((item) => item.stargazers_count) const stars = arrSum(numbers) const repositories = json.length diff --git a/api/networks/medium.js b/api/networks/medium.js index 2d70933..4e3b3f5 100644 --- a/api/networks/medium.js +++ b/api/networks/medium.js @@ -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 = await response.data const json = await JSON.parse(responseText.replace('])}while(1);', '')) const { collection } = json.payload diff --git a/api/networks/telegram.js b/api/networks/telegram.js index baded0d..626e9b4 100644 --- a/api/networks/telegram.js +++ b/api/networks/telegram.js @@ -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() diff --git a/api/networks/twitter.js b/api/networks/twitter.js index 4849d77..6b93656 100644 --- a/api/networks/twitter.js +++ b/api/networks/twitter.js @@ -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 = await response.data const followers = json[0].followers_count log( diff --git a/package-lock.json b/package-lock.json index 245781f..1e68dee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 3341dd4..56dae17 100644 --- a/package.json +++ b/package.json @@ -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",