diff --git a/endpoints/earthquake/index.js b/endpoints/earthquake/index.js index 4184d607..7b987e89 100644 --- a/endpoints/earthquake/index.js +++ b/endpoints/earthquake/index.js @@ -1,186 +1,168 @@ -/* eslint-disable no-prototype-builtins */ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable no-useless-escape */ -/* eslint-disable prefer-destructuring */ -const request = require('request') -const cheerio = require('cheerio') -const helpers = require('apis-helpers') -const app = require('../../server') - -const browser = helpers.browser - -/* - This function only handles the request part and calls callback with - the body - */ -function getEarthquakes(callback, params) { - // eslint-disable-next-line eqeqeq - const reqParams = !params ? { - url: 'http://hraun.vedur.is/ja/skjalftar/skjlisti.html', - headers: { 'User-Agent': browser() }, - // needed for some reason.. defaulting to ISO-8859-1 - encoding: 'binary', - } : params - - request(reqParams, (error, res, body) => { - if (error || res.statusCode !== 200) { - return callback(new Error('Could not retrieve the data from the data source')) - } - - return callback(error, body) - }) -} - -/* - * This function traverses the DOM, and looks for a JS variable that is included - * in the source of vedur.is. - * Note that it is synchronous. - */ -function parseJavaScriptVariable(body) { - // Work with empty string if scraping fails. - let res - let jsonString = '' - // Create a cheerio object from response body. - const $ = cheerio.load(body) - - // Find the variable inside one of the