diff --git a/bun.lockb b/bun.lockb index 40c9b15..deb4c6a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 43bc8d7..db03ef0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@elysiajs/swagger": "^0.2.0-rc.0", "cheerio": "^1.0.0-rc.12", "elysia": "^0.2.0-rc.0", - "elysia-rate-limit": "latest" + "elysia-rate-limit": "^1.0.3" }, "devDependencies": { "bun-types": "latest" diff --git a/src/functions/getLotto.ts b/src/functions/getLotto.ts index a1af1c4..4ea8836 100644 --- a/src/functions/getLotto.ts +++ b/src/functions/getLotto.ts @@ -1,14 +1,16 @@ import { load } from 'cheerio' +import type { CheerioAPI } from 'cheerio' + +const scrapeText = (cheerio: CheerioAPI) => (selector: string) => + cheerio(selector) + .map((_, el) => cheerio(el).text()) + .toArray() export const getLotto = async (targetId: string | number) => { const url = `https://news.sanook.com/lotto/check/${targetId}` const $ = load(await fetch(url).then(o => o.text())) - - const scrapeText = (selector: string) => - $(selector) - .map((_, el) => $(el).text()) - .toArray() + const scraper = scrapeText($) const [ date, @@ -25,31 +27,31 @@ export const getLotto = async (targetId: string | number) => { $('#contentPrint > header > h2') .text() .substring($('#contentPrint > header > h2').text().indexOf(' ') + 1), - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(1) > strong.lotto__number' ), // prizeFirst - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__sec--nearby > strong.lotto__number' ), // prizeFirstNear - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(2) > div > span.lotto__number' ), // prizeSecond - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(3) > div > span' ), // prizeThird - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--font-mini.lottocheck__sec--bdnoneads > div.lottocheck__box-item > span.lotto__number' ), // prizeForth - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(7) > div > span.lotto__number' ), // prizeFifth - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(2) > strong.lotto__number' ), // runningNumberFrontThree - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(3) > strong.lotto__number' ), // runningNumberBackThree - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(4) > strong.lotto__number' ), // runningNumberBackTwo ])