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
import { fetch } from "https://esm.town/v/std/fetch";
export const simpleSurf = (async () => {
// fetch these from the surfline page
const spotIds = [
"5842041f4e65fad6a770883f",
"5842041f4e65fad6a77088b4",
"5842041f4e65fad6a77088af",
"5842041f4e65fad6a770888b",
"5842041f4e65fad6a7708b32",
];
const spots = spotIds.join(",");
const surfForecast = await fetch(
`https://services.surfline.com/kbyg/spots/batch?units%5BswellHeight%5D=FT&units%5Btemperature%5D=F&units%5BtideHeight%5D=FT&units%5BwaveHeight%5D=FT&units%5BwindSpeed%5D=KTS&spotIds=${spots}`,
).then((r) => r.json()).then((d) => d.data);
return surfForecast.map((f) => ({
id: f._id,
name: f.name,
surflineURL: `https://www.surfline.com/surf-report/${
f.name.toLowerCase().replace(/[\s']/g, "-")
}/${f._id}`,
waterTemp: `${f.waterTemp.min}°`,
windSpeed: `${Math.round(f.wind.speed * 1.15078)}`,
windDirection: f.wind.directionType.replace("Cross-shore", "cross"),
waveHeight: `${f.waveHeight.min}-${f.waveHeight.max}`,
rating: f.rating.key,
tide: {
prevTideHeight: f.tide.previous.height,
prevTideTime: f.tide.previous.timestamp * 1000,
currTideHeight: f.tide.current.height,
currTideTime: f.tide.current.timestamp * 1000,
nextTideHeight: f.tide.next.height,
nextTideTime: f.tide.next.timestamp * 1000,
},
stream: f.cameras[0] ? f.cameras[0].streamUrl : "none",
}));
})();
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.