mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 08: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
|
||||
// announced by the UFC, otherwise list all fights without categorizing
|
||||
if (event.fightCard.length)
|
||||
description += event.fightCard.join("\n") + "\n";
|
||||
description = `${event.fightCard.join("\n")}\n`;
|
||||
if (event.mainCard.length)
|
||||
description +=
|
||||
"Main Card\n--------------------\n" +
|
||||
@@ -51,23 +51,22 @@ async function createICS() {
|
||||
if (event.prelims.length) {
|
||||
let prelimsTime = new Date(parseInt(event.prelimsTime) * 1000);
|
||||
let hoursAgo = (date - prelimsTime) / 1000 / 60 / 60;
|
||||
description +=
|
||||
`\nPrelims (${hoursAgo} hrs before Main)\n--------------------\n` +
|
||||
event.prelims.join("\n") +
|
||||
"\n";
|
||||
description += `\nPrelims (${hoursAgo} hrs before Main)\n--------------------\n${event.prelims.join(
|
||||
"\n"
|
||||
)}\n`;
|
||||
}
|
||||
if (event.earlyPrelims.length) {
|
||||
let earlyPrelimsTime = new Date(
|
||||
parseInt(event.earlyPrelimsTime) * 1000
|
||||
);
|
||||
let hoursAgo = (date - earlyPrelimsTime) / 1000 / 60 / 60;
|
||||
description +=
|
||||
`\nEarly Prelims (${hoursAgo} hrs before Main)\n--------------------\n` +
|
||||
event.earlyPrelims.join("\n") +
|
||||
"\n";
|
||||
if (!hoursAgo) console.log("hoursAgo", date, earlyPrelimsTime);
|
||||
description += `\nEarly Prelims (${hoursAgo} hrs before Main)\n--------------------\n${event.earlyPrelims.join(
|
||||
"\n"
|
||||
)}\n`;
|
||||
}
|
||||
description += "\n" + event.url;
|
||||
description += "\n\nAccurate as of " + dateTimestr;
|
||||
description += `\n${event.url}`;
|
||||
description += `\n\nAccurate as of ${dateTimestr}`;
|
||||
|
||||
let location = event.location;
|
||||
let uid = event.url;
|
||||
@@ -87,7 +86,7 @@ async function createICS() {
|
||||
console.log(events);
|
||||
|
||||
// Create UFC.ics
|
||||
writeFileSync(`UFC.ics`, createEvents(events).value);
|
||||
writeFileSync("UFC.ics", createEvents(events).value);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { decode } from "html-entities";
|
||||
* of URL strings of UFC events
|
||||
*/
|
||||
async function getEventLinks() {
|
||||
let url = `https://www.ufc.com/events`;
|
||||
let url = "https://www.ufc.com/events";
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const text = await response.text();
|
||||
@@ -17,7 +17,7 @@ async function getEventLinks() {
|
||||
// Extract the URLs of the relevant events from the DOM object
|
||||
let links = root.querySelectorAll(".c-card-event--result__headline");
|
||||
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:");
|
||||
@@ -110,15 +110,9 @@ async function getDetailsFromEventLink(url) {
|
||||
".c-listing-fight__ranks-row .js-listing-fight__corner-rank span"
|
||||
);
|
||||
ranks = ranks.map((rank) => rank?.innerText);
|
||||
let fightStr =
|
||||
"• " +
|
||||
red +
|
||||
(ranks[0] ? " (" + ranks[0] + ")" : "") +
|
||||
" vs. " +
|
||||
blue +
|
||||
(ranks[1] ? " (" + ranks[1] + ")" : "") +
|
||||
" @" +
|
||||
bout;
|
||||
let redRankStr = ranks[0] ? ` (${ranks[0]})` : "";
|
||||
let blueRankStr = ranks[1] ? ` (${ranks[1]})` : "";
|
||||
let fightStr = `• ${red}${redRankStr} vs. ${blue}${blueRankStr} @${bout}`;
|
||||
|
||||
// Deentitize HTML entities
|
||||
fightStr = decode(fightStr);
|
||||
@@ -168,7 +162,7 @@ async function getDetailsFromEventLink(url) {
|
||||
};
|
||||
return details;
|
||||
} 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