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
import { email } from "https://esm.town/v/std/email?v=9";
import { fetch } from "https://esm.town/v/std/fetch";
export async function reminders(interval: Interval) {
function* walk(node, path = []) {
yield node;
if (node && Array.isArray(node.value)) {
const arr = node.value;
for (let i = 0; i < arr.length; i++) {
yield* walk(arr[i], [...path, i]);
}
}
}
const comingUp = [];
// Parsed markwhen document
const response = await fetch("https://markwhen.com/rob.json");
const mw = await response.json();
// Alternatively, fetch a plaintext markwhen document from somewhere and parse it
/*
const response = await fetch("https://raw.githubusercontent.com/kochrt/kochrt.github.io/master/resume.mw")
const { parse } = await import("@markwhen/parser")
const mw = parse(await response.text())
*/
const events = mw.timelines[0].events;
const now = Date.now();
for (const node of walk(events)) {
if (!node.value.dateRangeIso) {
continue;
}
const from = Date.parse(node.value.dateRangeIso.fromDateTimeIso);
const diff = from - now;
// Takes place in the next hour
if (diff > 0 && diff < 60 * 60 * 1000) {
comingUp.push(node.value);
}
}
if (comingUp.length) {
await email({
text: comingUp.map((e) => e.eventString).join("\n\n"),
subject: `${comingUp.length} event${comingUp.length > 1 ? "s" : ""} coming up`,
});
}
}