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); - } - }); -}