Retrieve contest list && IDs from webpage. Create API endpoint to retrieve only the list of contests. Remove unnecessary debug logging
This commit is contained in:
parent
c24794be40
commit
4db5786579
|
@ -30,9 +30,15 @@ type Prize = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Contest = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
};
|
||||||
|
|
||||||
type EurmomilhoesData = {
|
type EurmomilhoesData = {
|
||||||
keys: Keys;
|
keys: Keys;
|
||||||
prizes: Prize[];
|
prizes: Prize[];
|
||||||
|
contests: Contest[];
|
||||||
};
|
};
|
||||||
|
|
||||||
function getKey(element: cheerio.Cheerio<cheerio.Element>) {
|
function getKey(element: cheerio.Cheerio<cheerio.Element>) {
|
||||||
|
@ -44,7 +50,6 @@ function getKey(element: cheerio.Cheerio<cheerio.Element>) {
|
||||||
|
|
||||||
// Not sure why, but an empty string is being inserted into the array
|
// Not sure why, but an empty string is being inserted into the array
|
||||||
numbers.forEach((value, i) => {
|
numbers.forEach((value, i) => {
|
||||||
console.log(value == "");
|
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
numbers.splice(i, 1);
|
numbers.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
@ -56,11 +61,26 @@ function getKey(element: cheerio.Cheerio<cheerio.Element>) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(stars);
|
|
||||||
|
|
||||||
return { numbers: numbers, stars: 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() {}
|
function storeData() {}
|
||||||
|
|
||||||
|
@ -83,23 +103,13 @@ async function scrapeWebpage() {
|
||||||
|
|
||||||
const $ = cheerio.load(result);
|
const $ = cheerio.load(result);
|
||||||
|
|
||||||
|
getContests($);
|
||||||
|
|
||||||
const keyLists = $(".betMiddle.twocol.regPad ul li");
|
const keyLists = $(".betMiddle.twocol.regPad ul li");
|
||||||
|
|
||||||
const orderedKey = getKey(keyLists.first());
|
const orderedKey = getKey(keyLists.first());
|
||||||
const sortedKey = getKey(keyLists.eq(1));
|
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 prizesDiv = $(".stripped.betMiddle.customfiveCol.regPad ul");
|
||||||
|
|
||||||
const prizes: Prize[] = [];
|
const prizes: Prize[] = [];
|
||||||
|
@ -138,6 +148,8 @@ async function scrapeWebpage() {
|
||||||
},
|
},
|
||||||
|
|
||||||
prizes: prizes,
|
prizes: prizes,
|
||||||
|
|
||||||
|
contests: getContests($),
|
||||||
};
|
};
|
||||||
|
|
||||||
resolve(data);
|
resolve(data);
|
||||||
|
|
|
@ -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;
|
|
@ -1,7 +1,8 @@
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
|
||||||
import handlePromise from "../../../util/promiseHandler";
|
import handlePromise from "../../../../util/promiseHandler";
|
||||||
import scrapeWebpage from "../../../scrapers/euromilhoes";
|
import scrapeWebpage from "../../../../scrapers/euromilhoes";
|
||||||
|
import contestsRouter from "../euromilhoes/contests";
|
||||||
|
|
||||||
const euromilhoesRouter = Router();
|
const euromilhoesRouter = Router();
|
||||||
|
|
||||||
|
@ -16,4 +17,6 @@ euromilhoesRouter.get("/", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
euromilhoesRouter.use("/contests", contestsRouter);
|
||||||
|
|
||||||
export default euromilhoesRouter;
|
export default euromilhoesRouter;
|
Loading…
Reference in New Issue