From 008e7c1cf434d3be184b2e46ad8e493dd0e6dd33 Mon Sep 17 00:00:00 2001 From: Amelia <9247739-limesey@users.noreply.gitlab.com> Date: Sat, 4 Jun 2022 17:13:03 +0100 Subject: [PATCH] File renamed from scaper.ts to scraper.ts --- src/scaper.ts | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/scaper.ts diff --git a/src/scaper.ts b/src/scaper.ts deleted file mode 100644 index 6f30a2a..0000000 --- a/src/scaper.ts +++ /dev/null @@ -1,37 +0,0 @@ -import axios from "axios"; -import * as cheerio from "cheerio"; - -import * as fs from "fs"; - -// TODO: Move promise handling function to util file -async function handlePromise(promise: Promise) { - try { - const data = await promise; - - return [true, data]; - } catch (err) { - return [false, err]; - } -} - -export default function scrapeData(url: string) { - return new Promise(async function (resolve, reject) { - const [success, data] = await handlePromise(axios.get(url)); - - if (success) { - const html = data.data; - - const $ = cheerio.load(html); - - // For now, only scraping the first/top meaning; - - const meaning = $(".meaning.mb-4").first().text().trim(); - - resolve(meaning); - } else { - console.error(data); - - reject(data); - } - }); -}