diff --git a/src/scrapers/euromilhoes.ts b/src/scrapers/euromilhoes.ts index 7e5e15f..9bd6e95 100644 --- a/src/scrapers/euromilhoes.ts +++ b/src/scrapers/euromilhoes.ts @@ -30,9 +30,15 @@ type Prize = { }; }; +type Contest = { + id: string; + title: string; +}; + type EurmomilhoesData = { keys: Keys; prizes: Prize[]; + contests: Contest[]; }; function getKey(element: cheerio.Cheerio) { @@ -44,7 +50,6 @@ function getKey(element: cheerio.Cheerio) { // Not sure why, but an empty string is being inserted into the array numbers.forEach((value, i) => { - console.log(value == ""); if (value == "") { numbers.splice(i, 1); } @@ -56,11 +61,26 @@ function getKey(element: cheerio.Cheerio) { } }); - console.log(stars); - return { numbers: numbers, stars: stars }; } +/** + * Scrape contests data from the selection menu + */ +function getContests($: cheerio.CheerioAPI) { + const selectionMenuOptions = $("select[name=selectContest]").find("option"); + const contests: Contest[] = []; + + selectionMenuOptions.each(function (elem, i) { + const id = $(this).attr("value")!; + const title = $(this).text(); + + contests.push({ id: id, title: title }); + }); + + return contests; +} + /** */ function storeData() {} @@ -83,23 +103,13 @@ async function scrapeWebpage() { const $ = cheerio.load(result); + getContests($); + 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[] = []; @@ -138,6 +148,8 @@ async function scrapeWebpage() { }, prizes: prizes, + + contests: getContests($), }; resolve(data); diff --git a/src/server/routes/api/euromilhoes/contests.ts b/src/server/routes/api/euromilhoes/contests.ts new file mode 100644 index 0000000..e1152c4 --- /dev/null +++ b/src/server/routes/api/euromilhoes/contests.ts @@ -0,0 +1,19 @@ +import { Router } from "express"; + +import scrapeWebpage from "../../../../scrapers/euromilhoes"; +import handlePromise from "../../../../util/promiseHandler"; + +const contestsRouter = Router(); + +contestsRouter.get("/", async (req, res) => { + const [resolved, result] = await handlePromise(scrapeWebpage()); + + if (resolved == true) { + res.json(result.contests); + } else { + console.error(result); + res.send(500); + } +}); + +export default contestsRouter; diff --git a/src/server/routes/api/euromilhoes.ts b/src/server/routes/api/euromilhoes/euromilhoes.ts similarity index 59% rename from src/server/routes/api/euromilhoes.ts rename to src/server/routes/api/euromilhoes/euromilhoes.ts index 84ecce5..f0c42cc 100644 --- a/src/server/routes/api/euromilhoes.ts +++ b/src/server/routes/api/euromilhoes/euromilhoes.ts @@ -1,7 +1,8 @@ import { Router } from "express"; -import handlePromise from "../../../util/promiseHandler"; -import scrapeWebpage from "../../../scrapers/euromilhoes"; +import handlePromise from "../../../../util/promiseHandler"; +import scrapeWebpage from "../../../../scrapers/euromilhoes"; +import contestsRouter from "../euromilhoes/contests"; const euromilhoesRouter = Router(); @@ -16,4 +17,6 @@ euromilhoesRouter.get("/", async (req, res) => { } }); +euromilhoesRouter.use("/contests", contestsRouter); + export default euromilhoesRouter;