Add error printing && fix key scraping. Added function to scrape keys, in order to clean code
This commit is contained in:
parent
e88a6b2d0a
commit
4391df8c1a
|
@ -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<cheerio.Element>) {
|
||||
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,
|
||||
|
|
|
@ -11,6 +11,7 @@ euromilhoesRouter.get("/", async (req, res) => {
|
|||
if (resolved == true) {
|
||||
res.json(result);
|
||||
} else {
|
||||
console.error(result);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue