feat: added script to create 2026 schedule
This commit is contained in:
1 parent
4399d1b434
commit
ab81a1c4be
1 file changed
+171
+171
@@ -0,0 +1,171 @@
|
|||||||
|
const URL = "https://ballephenix.com";
|
||||||
|
const USERNAME = "XXXXXX";
|
||||||
|
const PASSWORD = "XXXXXX";
|
||||||
|
|
||||||
|
type PreGame = {
|
||||||
|
date: string;
|
||||||
|
time: string;
|
||||||
|
home: string;
|
||||||
|
away: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WeekDay {
|
||||||
|
readonly year: number;
|
||||||
|
readonly month: number;
|
||||||
|
readonly day: number;
|
||||||
|
|
||||||
|
constructor(iso: string) {
|
||||||
|
const [y, m, d] = iso.split("-").map(Number);
|
||||||
|
this.year = y;
|
||||||
|
this.month = m;
|
||||||
|
this.day = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
next(): WeekDay {
|
||||||
|
const d = new Date(this.year, this.month - 1, this.day + 7);
|
||||||
|
return new WeekDay(
|
||||||
|
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
saturday(): WeekDay {
|
||||||
|
const d = new Date(this.year, this.month - 1, this.day + 2);
|
||||||
|
return new WeekDay(
|
||||||
|
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `${this.year}-${String(this.month).padStart(2, "0")}-${String(this.day).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const w1 = new WeekDay("2026-05-14");
|
||||||
|
const w2 = w1.next();
|
||||||
|
const w3 = w2.next();
|
||||||
|
const w4 = w3.next();
|
||||||
|
// skip Saint-Jean
|
||||||
|
const w5 = w4.next().next();
|
||||||
|
const w6 = w5.next();
|
||||||
|
const w7 = w6.next();
|
||||||
|
const w8 = w7.next();
|
||||||
|
const w9 = w8.next();
|
||||||
|
const w10 = w9.next();
|
||||||
|
const w11 = w10.next();
|
||||||
|
const w12 = w11.next();
|
||||||
|
// const tournament = w12.saturday();
|
||||||
|
const w13 = w12.next();
|
||||||
|
const w14 = w13.next();
|
||||||
|
|
||||||
|
const games: PreGame[] = [
|
||||||
|
{ date: `${w1}`, time: "18:45", home: "gris", away: "bleu" },
|
||||||
|
{ date: `${w1}`, time: "20:15", home: "mauve", away: "jaune" },
|
||||||
|
|
||||||
|
{ date: `${w2}`, time: "18:45", home: "jaune", away: "gris" },
|
||||||
|
{ date: `${w2}`, time: "20:15", home: "bleu", away: "mauve" },
|
||||||
|
|
||||||
|
{ date: `${w3}`, time: "18:45", home: "gris", away: "mauve" },
|
||||||
|
{ date: `${w3}`, time: "20:15", home: "jaune", away: "bleu" },
|
||||||
|
|
||||||
|
{ date: `${w4}`, time: "18:45", home: "mauve", away: "bleu" },
|
||||||
|
{ date: `${w4}`, time: "20:15", home: "gris", away: "jaune" },
|
||||||
|
|
||||||
|
{ date: `${w5}`, time: "18:45", home: "bleu", away: "jaune" },
|
||||||
|
{ date: `${w5}`, time: "20:15", home: "mauve", away: "gris" },
|
||||||
|
|
||||||
|
{ date: `${w6}`, time: "18:45", home: "jaune", away: "mauve" },
|
||||||
|
{ date: `${w6}`, time: "20:15", home: "bleu", away: "gris" },
|
||||||
|
|
||||||
|
{ date: `${w7}`, time: "18:45", home: "gris", away: "bleu" },
|
||||||
|
{ date: `${w7}`, time: "20:15", home: "mauve", away: "jaune" },
|
||||||
|
|
||||||
|
{ date: `${w8}`, time: "18:45", home: "jaune", away: "gris" },
|
||||||
|
{ date: `${w8}`, time: "20:15", home: "bleu", away: "mauve" },
|
||||||
|
|
||||||
|
{ date: `${w9}`, time: "18:45", home: "gris", away: "mauve" },
|
||||||
|
{ date: `${w9}`, time: "20:15", home: "jaune", away: "bleu" },
|
||||||
|
|
||||||
|
{ date: `${w10}`, time: "18:45", home: "mauve", away: "bleu" },
|
||||||
|
{ date: `${w10}`, time: "20:15", home: "gris", away: "jaune" },
|
||||||
|
{ date: `${w10}`, time: "21:35", home: "jaune", away: "gris" },
|
||||||
|
|
||||||
|
{ date: `${w11}`, time: "18:45", home: "bleu", away: "jaune" },
|
||||||
|
{ date: `${w11}`, time: "20:15", home: "mauve", away: "gris" },
|
||||||
|
|
||||||
|
{ date: `${w12}`, time: "18:45", home: "jaune", away: "mauve" },
|
||||||
|
{ date: `${w12}`, time: "20:15", home: "bleu", away: "gris" },
|
||||||
|
|
||||||
|
// { date: `${tournament}`, time: "09:00", home: "gris", away: "bleu" },
|
||||||
|
// { date: `${tournament}`, time: "10:30", home: "mauve", away: "jaune" },
|
||||||
|
// { date: `${tournament}`, time: "15:30", home: "bleu", away: "mauve" },
|
||||||
|
|
||||||
|
{ date: `${w13}`, time: "18:45", home: "gris", away: "mauve" },
|
||||||
|
{ date: `${w13}`, time: "20:15", home: "jaune", away: "bleu" },
|
||||||
|
|
||||||
|
{ date: `${w14}`, time: "18:45", home: "gris", away: "bleu" },
|
||||||
|
{ date: `${w14}`, time: "20:15", home: "mauve", away: "jaune" },
|
||||||
|
];
|
||||||
|
|
||||||
|
function extractCookies(headers: Headers): string {
|
||||||
|
const cookies: string[] = [];
|
||||||
|
for (const value of headers.getSetCookie()) {
|
||||||
|
cookies.push(value.split(";")[0]);
|
||||||
|
}
|
||||||
|
return cookies.join("; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function login(): Promise<string> {
|
||||||
|
const res = await fetch(
|
||||||
|
`${URL}/login?username=${encodeURIComponent(USERNAME)}&password=${encodeURIComponent(PASSWORD)}`,
|
||||||
|
{ redirect: "manual" },
|
||||||
|
);
|
||||||
|
if (res.status !== 302) {
|
||||||
|
throw new Error(`Login failed with status ${res.status}`);
|
||||||
|
}
|
||||||
|
return extractCookies(res.headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createGame(cookie: string, game: PreGame): Promise<void> {
|
||||||
|
const body = new URLSearchParams({
|
||||||
|
"game-date": game.date,
|
||||||
|
"game-time": game.time,
|
||||||
|
"home-team": game.home,
|
||||||
|
"away-team": game.away,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(`${URL}/membre/new-game`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
Cookie: cookie,
|
||||||
|
},
|
||||||
|
body: body.toString(),
|
||||||
|
redirect: "manual",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status >= 400) {
|
||||||
|
const text = await res.text();
|
||||||
|
throw new Error(
|
||||||
|
`Failed to create ${game.date} ${game.time} ${game.home} vs ${game.away}: ${text}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await res.body?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log("Logging in...");
|
||||||
|
const cookie = await login();
|
||||||
|
console.log("Logged in.\n");
|
||||||
|
|
||||||
|
for (const game of games) {
|
||||||
|
console.log(
|
||||||
|
`Creating: ${game.date} ${game.time} ${game.home} vs ${game.away}`,
|
||||||
|
);
|
||||||
|
await createGame(cookie, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\nDone. ${games.length} games created.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
Reference in new issue
Block a user