mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 00:38:30 -07:00
implement createICS function in index.js
This commit is contained in:
1 parent
8f46b25d06
commit
50a511af99
5 files changed
+128
-7
No files matched your search
@@ -1 +0,0 @@
|
||||
node_modules
|
||||
@@ -0,0 +1,41 @@
|
||||
import { getAllDetailedEvents } from "./scrape.js";
|
||||
import { writeFileSync } from "fs";
|
||||
import { createEvents } from "ics";
|
||||
|
||||
async function createICS() {
|
||||
try {
|
||||
let events = await getAllDetailedEvents();
|
||||
|
||||
events = events.map((event) => {
|
||||
let date = new Date(parseInt(event.date) * 1000);
|
||||
let start = [
|
||||
date.getFullYear(),
|
||||
date.getMonth() + 1,
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
];
|
||||
let duration = { hours: 3 };
|
||||
let title = event.name;
|
||||
let description = "";
|
||||
if (event.fightCard.length)
|
||||
description += event.fightCard.join("\n") + "\n";
|
||||
if (event.mainCard.length)
|
||||
description +=
|
||||
"Main Card\n----------\n" + event.mainCard.join("\n") + "\n";
|
||||
if (event.prelims.length)
|
||||
description +=
|
||||
"\nPrelims\n----------\n" + event.prelims.join("\n") + "\n";
|
||||
let location = event.location;
|
||||
let url = event.url;
|
||||
let uid = event.url;
|
||||
return { start, duration, title, description, location, url, uid };
|
||||
});
|
||||
|
||||
writeFileSync(`UFC.ics`, createEvents(events).value);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
createICS();
|
||||
Generated
+71
@@ -10,6 +10,7 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"html-entities": "^2.4.0",
|
||||
"ics": "^3.4.0",
|
||||
"node-html-parser": "^6.1.9"
|
||||
}
|
||||
},
|
||||
@@ -139,6 +140,34 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/ics": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ics/-/ics-3.4.0.tgz",
|
||||
"integrity": "sha512-ewKO7nF5BKhVKas3XmjB1siXdhJ7OvojY+HmD1ik/lozuzcZdy+Wt6IbB2San2gvHZAMUZhTa4UQyCE1I8e+sw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.1.23",
|
||||
"yup": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "3.3.6",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz",
|
||||
"integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
],
|
||||
"bin": {
|
||||
"nanoid": "bin/nanoid.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/node-html-parser": {
|
||||
"version": "6.1.9",
|
||||
"resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-6.1.9.tgz",
|
||||
@@ -160,6 +189,48 @@
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/nth-check?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/property-expr": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.5.tgz",
|
||||
"integrity": "sha512-IJUkICM5dP5znhCckHSv30Q4b5/JA5enCtkRHYaOVOAocnH/1BQEYTC5NMfT3AVl/iXKdr3aqQbQn9DxyWknwA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tiny-case": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz",
|
||||
"integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/toposort": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
|
||||
"integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/type-fest": {
|
||||
"version": "2.19.0",
|
||||
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz",
|
||||
"integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12.20"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/yup": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/yup/-/yup-1.2.0.tgz",
|
||||
"integrity": "sha512-PPqYKSAXjpRCgLgLKVGPA33v5c/WgEx3wi6NFjIiegz90zSwyMpvTFp/uGcVnnbx6to28pgnzp/q8ih3QRjLMQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"property-expr": "^2.0.5",
|
||||
"tiny-case": "^1.0.3",
|
||||
"toposort": "^2.0.2",
|
||||
"type-fest": "^2.19.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"html-entities": "^2.4.0",
|
||||
"ics": "^3.4.0",
|
||||
"node-html-parser": "^6.1.9"
|
||||
},
|
||||
"type": "module"
|
||||
|
||||
@@ -37,9 +37,18 @@ async function getDetailsFromEventLink(url) {
|
||||
let prelims = [];
|
||||
|
||||
function convertLiToStr(li) {
|
||||
let bout = li
|
||||
.querySelector(".c-listing-fight__class-text")
|
||||
.innerText.replace(" Bout", "");
|
||||
let bout = li.querySelector(".c-listing-fight__class-text").innerText;
|
||||
if (bout.includes("Strawweight")) bout = "115";
|
||||
else if (bout.includes("Flyweight")) bout = "125";
|
||||
else if (bout.includes("Bantamweight")) bout = "135";
|
||||
else if (bout.includes("Featherweight")) bout = "145";
|
||||
else if (bout.includes("Lightweight")) bout = "155";
|
||||
else if (bout.includes("Welterweight")) bout = "170";
|
||||
else if (bout.includes("Middleweight")) bout = "185";
|
||||
else if (bout.includes("Light Heavyweight")) bout = "205";
|
||||
else if (bout.includes("Heavyweight")) bout = "265";
|
||||
else if (bout.includes("Catchweight")) bout = "CW";
|
||||
|
||||
let red = li
|
||||
.querySelector(".c-listing-fight__corner-name--red")
|
||||
.innerText.replaceAll("\n", "")
|
||||
@@ -55,14 +64,14 @@ async function getDetailsFromEventLink(url) {
|
||||
);
|
||||
ranks = ranks.map((rank) => rank?.innerText);
|
||||
let fightStr =
|
||||
"• " +
|
||||
red +
|
||||
(ranks[0] ? " (" + ranks[0] + ")" : "") +
|
||||
" vs. " +
|
||||
blue +
|
||||
(ranks[1] ? " (" + ranks[1] + ")" : "") +
|
||||
" [" +
|
||||
bout +
|
||||
"]";
|
||||
" @" +
|
||||
bout;
|
||||
fightStr = decode(fightStr);
|
||||
return fightStr;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user