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 { fetch } from "https://esm.town/v/std/fetch";
export const dsnyEventsFeed = (async () => {
const ics = await import("npm:ics");
const events = await fetch(
"https://a827-donatenyc.nyc.gov/DSNYApi/api/Events/GetAllByBorough?borough=",
)
.then((r) => r.json());
const converted = events.map((evt) => {
const dp = evt.FromDateTime.split(/[\/\s:]+/);
return {
// pts: dp,
// am: dp[6],
// dt: evt.FromDateTime,
// year, month, day, hour, minute
start: [
dp[2],
dp[0],
dp[1],
+dp[3] + 4 + (dp[6] === "AM" ? 0 : 12),
dp[4],
]
.map((n) => parseInt(n, 10)),
title: evt.EventName,
description: evt.Description,
location: evt.Street + " " + evt.City + " " + evt.State + " " + evt.Zip,
url: `https://${evt.Website}`,
// geo: { lat: 40.0095, lon: 105.2669 },
busyStatus: "BUSY",
organizer: { name: evt.Name, email: evt.EmailAddress },
attendees: [],
};
});
const { error, value } = ics.createEvents(converted);
return new Response(
/* JSON.stringify(converted) || */ value || JSON.stringify(error),
{
headers: {
"Content-Type": "text/calendar",
},
},
);
});