-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathical.ts
70 lines (66 loc) · 1.97 KB
/
ical.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import tz from "npm:@touch4it/[email protected]";
import ical, {
ICalAlarmType,
ICalEvent,
ICalEventData,
ICalEventTransparency,
} from "npm:[email protected]";
import { GP } from "./interfaces.ts";
import { getGPS } from "./openkv.ts";
const newline = `\n`;
const x = { "X-APPLE-TRAVEL-ADVISORY-BEHAVIOR": "AUTOMATIC" };
function getText(gps: GP[]) {
// const timezone = "Europe/Amsterdam";
const timezone = "GMT Standard Time";
const cal = ical({
name: "Formula 1",
description: "Race Events",
// timezone,
ttl: 3600 * 24,
prodId: {
company: "Sander Spilleman",
product: "Formula 1 Race Events",
language: "NL",
},
// timezone: timezone,
timezone: {
name: timezone,
generator: tz.getVtimezoneComponent,
},
});
for (const gp of gps) {
for (const event of gp.events) {
let lines: string[] = [];
if (gp.stats && gp.stats.length > 0) {
lines = gp.stats.map((d) => `${d.name}: ${d.value}`);
}
lines.push(`${newline}https://viaplay.com/sport/motorsport/formula-1`);
const description = { plain: lines.join(newline) };
const current = new Date();
const data: ICalEventData = {
allDay: false,
start: new Date(event.start),
end: new Date(event.end),
summary: `${gp.name}: ${event.name}`,
description,
created: current,
lastModified: current,
transparency: ICalEventTransparency.OPAQUE,
x,
floating: false,
timezone,
};
const e: ICalEvent = cal.createEvent(data);
e.createAlarm({ type: ICalAlarmType.display, trigger: 3600 });
e.createAlarm({ type: ICalAlarmType.audio, trigger: 3600 });
}
}
return cal.toString();
}
export const getIcal = async (year: number) => {
// const gps = (await getGPS(year)).filter((g) => g.name === "GP Monaco");
const gps = await getGPS(year);
const txt = getText(gps);
return txt;
};
// console.log(await getIcal(2024));