Skip to content

Commit

Permalink
chore: staged changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Mar 10, 2023
1 parent 18d1544 commit dbef7ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 16 additions & 14 deletions src/functions/getLotto.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
])
Expand Down

0 comments on commit dbef7ec

Please sign in to comment.