From 63e3403b8b93f1008b3d1ad8c01e2811f229a2fb Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Sat, 2 Oct 2021 16:01:48 +0530 Subject: [PATCH] feat: remove API implementations Fetching data from web APIs is not a valid algorithm. --- Web-Programming/OpenWeatherMaps.js | 31 ------------------------------ Web-Programming/StockPrice.js | 30 ----------------------------- 2 files changed, 61 deletions(-) delete mode 100644 Web-Programming/OpenWeatherMaps.js delete mode 100644 Web-Programming/StockPrice.js diff --git a/Web-Programming/OpenWeatherMaps.js b/Web-Programming/OpenWeatherMaps.js deleted file mode 100644 index 7f1d4e31b..000000000 --- a/Web-Programming/OpenWeatherMaps.js +++ /dev/null @@ -1,31 +0,0 @@ -const fetch = require('node-fetch') - -const APPID = '' // <-- Put your OpenWeatherMap appid here! -const URL_BASE = 'http://api.openweathermap.org/data/2.5/' - -async function currentWeather (location) { - const response = await fetch(`${URL_BASE}weather?q=${location}&appid=${APPID}`) - const data = await response.json() - return data -} - -async function weatherForecast (location) { - const response = await fetch(`${URL_BASE}forecast?q=${location}&appid=${APPID}`) - const data = await response.json() - return data -} - -async function oneCallApi (latitude, longitude) { - const response = await fetch(`${URL_BASE}onecall?lat=${latitude}&lon=${longitude}&appid=${APPID}`) - const data = await response.json() - return data -} - -currentWeather('Kolkata') - .then(data => console.log(data)) - -weatherForecast('Kolkata') - .then(data => console.log(data)) - -oneCallApi(55.68, 12.57) - .then(data => console.log(data)) diff --git a/Web-Programming/StockPrice.js b/Web-Programming/StockPrice.js deleted file mode 100644 index f2e656305..000000000 --- a/Web-Programming/StockPrice.js +++ /dev/null @@ -1,30 +0,0 @@ -const fetch = require('node-fetch') -const jsdom = require('jsdom') - -// function to get the stock price from the given symbol -async function getStockPrice (stockSymbol) { - // parsing the html page body - const url = `https://in.finance.yahoo.com/lookup?s=$${stockSymbol}` - const response = await fetch(url) - const pageBody = await response.text() - const dom = new jsdom.JSDOM(pageBody, 'text/html') - // returning the price as a number - return parseFloat(dom.window.document.querySelectorAll('td')[2].textContent.replace(/,/g, '')) -} - -async function main () { - // Using async await to ensure synchronous behaviour - await getStockPrice('GOOGL') - .then(response => console.log(`GOOGL stock price: $ ${response}`)) - - await getStockPrice('AAPL') - .then(response => console.log(`AAPL stock price: $ ${response}`)) - - await getStockPrice('MSFT') - .then(response => console.log(`MSFT stock price: $ ${response}`)) - - await getStockPrice('AMZN') - .then(response => console.log(`AMZN stock price: $ ${response}`)) -} - -main()