1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { fetch } from "https://esm.town/v/std/fetch";
export const getTideTimes = (async () => {
const cheerio = await import("npm:cheerio");
const response = await fetch(
"https://www.worldtides.info/tidestations/Europe/Ireland/DUBLIN_(NORTH_WALL)",
);
const body = await response.text();
const $ = cheerio.load(body);
const tableRows = $("table.table.table-bordered tbody tr");
const tideTimes = [];
for (let i = 1; i < tableRows.length; i++) {
const row = tableRows[i];
const tide = $(row).find("td:nth-child(1)").text().trim();
const time = $(row).find("td:nth-child(2)").text().trim();
const heightStr = $(row).find("td:nth-child(3)").text().trim();
const regex = /([\d.]+)\s*m/;
const match = regex.exec(heightStr);
const heightInMeters = match[0];
tideTimes.push({ tide, time, height: heightInMeters });
}
return tideTimes;
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023