mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 00:38:30 -07:00
Change strings to use template literals
This commit is contained in:
1 parent
d8a4e63210
commit
4092a2e2f5
2 files changed
+17
-24
No files matched your search
@@ -42,7 +42,7 @@ async function createICS() {
|
|||||||
// Distinguish between main card and prelims if this information has been
|
// Distinguish between main card and prelims if this information has been
|
||||||
// announced by the UFC, otherwise list all fights without categorizing
|
// announced by the UFC, otherwise list all fights without categorizing
|
||||||
if (event.fightCard.length)
|
if (event.fightCard.length)
|
||||||
description += event.fightCard.join("\n") + "\n";
|
description = `${event.fightCard.join("\n")}\n`;
|
||||||
if (event.mainCard.length)
|
if (event.mainCard.length)
|
||||||
description +=
|
description +=
|
||||||
"Main Card\n--------------------\n" +
|
"Main Card\n--------------------\n" +
|
||||||
@@ -51,23 +51,22 @@ async function createICS() {
|
|||||||
if (event.prelims.length) {
|
if (event.prelims.length) {
|
||||||
let prelimsTime = new Date(parseInt(event.prelimsTime) * 1000);
|
let prelimsTime = new Date(parseInt(event.prelimsTime) * 1000);
|
||||||
let hoursAgo = (date - prelimsTime) / 1000 / 60 / 60;
|
let hoursAgo = (date - prelimsTime) / 1000 / 60 / 60;
|
||||||
description +=
|
description += `\nPrelims (${hoursAgo} hrs before Main)\n--------------------\n${event.prelims.join(
|
||||||
`\nPrelims (${hoursAgo} hrs before Main)\n--------------------\n` +
|
"\n"
|
||||||
event.prelims.join("\n") +
|
)}\n`;
|
||||||
"\n";
|
|
||||||
}
|
}
|
||||||
if (event.earlyPrelims.length) {
|
if (event.earlyPrelims.length) {
|
||||||
let earlyPrelimsTime = new Date(
|
let earlyPrelimsTime = new Date(
|
||||||
parseInt(event.earlyPrelimsTime) * 1000
|
parseInt(event.earlyPrelimsTime) * 1000
|
||||||
);
|
);
|
||||||
let hoursAgo = (date - earlyPrelimsTime) / 1000 / 60 / 60;
|
let hoursAgo = (date - earlyPrelimsTime) / 1000 / 60 / 60;
|
||||||
description +=
|
if (!hoursAgo) console.log("hoursAgo", date, earlyPrelimsTime);
|
||||||
`\nEarly Prelims (${hoursAgo} hrs before Main)\n--------------------\n` +
|
description += `\nEarly Prelims (${hoursAgo} hrs before Main)\n--------------------\n${event.earlyPrelims.join(
|
||||||
event.earlyPrelims.join("\n") +
|
"\n"
|
||||||
"\n";
|
)}\n`;
|
||||||
}
|
}
|
||||||
description += "\n" + event.url;
|
description += `\n${event.url}`;
|
||||||
description += "\n\nAccurate as of " + dateTimestr;
|
description += `\n\nAccurate as of ${dateTimestr}`;
|
||||||
|
|
||||||
let location = event.location;
|
let location = event.location;
|
||||||
let uid = event.url;
|
let uid = event.url;
|
||||||
@@ -87,7 +86,7 @@ async function createICS() {
|
|||||||
console.log(events);
|
console.log(events);
|
||||||
|
|
||||||
// Create UFC.ics
|
// Create UFC.ics
|
||||||
writeFileSync(`UFC.ics`, createEvents(events).value);
|
writeFileSync("UFC.ics", createEvents(events).value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { decode } from "html-entities";
|
|||||||
* of URL strings of UFC events
|
* of URL strings of UFC events
|
||||||
*/
|
*/
|
||||||
async function getEventLinks() {
|
async function getEventLinks() {
|
||||||
let url = `https://www.ufc.com/events`;
|
let url = "https://www.ufc.com/events";
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
@@ -17,7 +17,7 @@ async function getEventLinks() {
|
|||||||
// Extract the URLs of the relevant events from the DOM object
|
// Extract the URLs of the relevant events from the DOM object
|
||||||
let links = root.querySelectorAll(".c-card-event--result__headline");
|
let links = root.querySelectorAll(".c-card-event--result__headline");
|
||||||
links = links.map(
|
links = links.map(
|
||||||
(html) => "https://www.ufc.com" + html.firstChild.getAttribute("href")
|
(html) => `https://www.ufc.com${html.firstChild.getAttribute("href")}`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("\nEvent links found:");
|
console.log("\nEvent links found:");
|
||||||
@@ -110,15 +110,9 @@ async function getDetailsFromEventLink(url) {
|
|||||||
".c-listing-fight__ranks-row .js-listing-fight__corner-rank span"
|
".c-listing-fight__ranks-row .js-listing-fight__corner-rank span"
|
||||||
);
|
);
|
||||||
ranks = ranks.map((rank) => rank?.innerText);
|
ranks = ranks.map((rank) => rank?.innerText);
|
||||||
let fightStr =
|
let redRankStr = ranks[0] ? ` (${ranks[0]})` : "";
|
||||||
"• " +
|
let blueRankStr = ranks[1] ? ` (${ranks[1]})` : "";
|
||||||
red +
|
let fightStr = `• ${red}${redRankStr} vs. ${blue}${blueRankStr} @${bout}`;
|
||||||
(ranks[0] ? " (" + ranks[0] + ")" : "") +
|
|
||||||
" vs. " +
|
|
||||||
blue +
|
|
||||||
(ranks[1] ? " (" + ranks[1] + ")" : "") +
|
|
||||||
" @" +
|
|
||||||
bout;
|
|
||||||
|
|
||||||
// Deentitize HTML entities
|
// Deentitize HTML entities
|
||||||
fightStr = decode(fightStr);
|
fightStr = decode(fightStr);
|
||||||
@@ -168,7 +162,7 @@ async function getDetailsFromEventLink(url) {
|
|||||||
};
|
};
|
||||||
return details;
|
return details;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error("Failed to retrieve event: " + url + "\n" + error);
|
throw new Error(`Failed to retrieve event: ${url}\n${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user