diff --git a/src/scrapers/euromilhoes.ts b/src/scrapers/euromilhoes.ts index 8e01de7..c1990d1 100644 --- a/src/scrapers/euromilhoes.ts +++ b/src/scrapers/euromilhoes.ts @@ -9,8 +9,8 @@ const EUROMILHOES_URL = "https://www.jogossantacasa.pt/web/SCCartazResult/euroMilhoes"; type Key = { - numbers: string; - stars: string; + numbers: string[]; + stars: string[]; }; type Keys = { @@ -35,6 +35,16 @@ type EurmomilhoesData = { prizes: Prize[]; }; +function getKey(element: cheerio.Cheerio) { + const elementText = element.text().trim(); + let splitKey = elementText.split("+"); + + const numbers = splitKey[0].split(" "); + const stars = splitKey[1].split(" "); + + return { numbers: numbers, stars: stars }; +} + /** */ function storeData() {} @@ -58,12 +68,22 @@ async function scrapeWebpage() { const $ = cheerio.load(result); const keyLists = $(".betMiddle.twocol.regPad ul li"); + + const orderedKey = getKey(keyLists.first()); + const sortedKey = getKey(keyLists.eq(1)); + + /* console.log(keyLists.first().text().trim()); + console.log(keyLists.eq(1).text().trim()); + const key = keyLists.first().text().trim(); let splitKey = key.split("+"); const orderedKey = keyLists.eq(1).text(); splitKey = orderedKey.split("+"); + const orderedKeyNumbers = splitKey[0].split(" "); + const orderedKeyStars = splitKey[1].split(" "); */ + const prizesDiv = $(".stripped.betMiddle.customfiveCol.regPad ul"); const prizes: Prize[] = []; @@ -97,8 +117,8 @@ async function scrapeWebpage() { const data: EurmomilhoesData = { keys: { - orderedKey: { numbers: "0", stars: "0" }, - sortedKey: { numbers: "0", stars: "0" }, + orderedKey: orderedKey, + sortedKey: sortedKey, }, prizes: prizes, diff --git a/src/server/routes/api/euromilhoes.ts b/src/server/routes/api/euromilhoes.ts index b168fa8..84ecce5 100644 --- a/src/server/routes/api/euromilhoes.ts +++ b/src/server/routes/api/euromilhoes.ts @@ -11,6 +11,7 @@ euromilhoesRouter.get("/", async (req, res) => { if (resolved == true) { res.json(result); } else { + console.error(result); res.sendStatus(500); } });