Fixed script for tidal data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
GeorgeWebberley 2026-01-28 12:22:12 +01:00
parent 759f38eae5
commit 0804c0aa74

View file

@ -11,16 +11,14 @@ const writeApi = client.getWriteApi(org, bucket);
const lat = 51.58;
const lon = -4.29;
const marineUrl = `https://marine-api.open-meteo.com/v1/marine?latitude=${lat}&longitude=${lon}&current=swell_wave_height,swell_wave_period,swell_wave_direction,wind_wave_height`;
const marineUrl = `https://marine-api.open-meteo.com/v1/marine?latitude=${lat}&longitude=${lon}&current=swell_wave_height,swell_wave_period,swell_wave_direction&hourly=sealevel`;
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current=wind_speed_10m,wind_direction_10m`;
const tideUrl = `https://flood-api.open-meteo.com/v1/flood?latitude=${lat}&longitude=${lon}&daily=sealevel_max,sealevel_min&hourly=sealevel`;
async function fetchSurfData() {
try {
const [marineRes, weatherRes, tideRes] = await Promise.all([
const [marineRes, weatherRes] = await Promise.all([
axios.get(marineUrl),
axios.get(weatherUrl),
axios.get(tideUrl)
]);
const beachTime = new Intl.DateTimeFormat('en-GB', {
@ -30,10 +28,10 @@ async function fetchSurfData() {
}).format(new Date());
const currentHour = parseInt(beachTime);
const hourlyData = tideRes.data.hourly.sealevel;
const currentTideHeight = hourlyData[currentHour];
const nextHour = (currentHour + 1) % hourlyData.length;
const nextTideHeight = hourlyData[nextHour];
const hourlyTides = marineRes.data.hourly.sealevel;
const currentTideHeight = hourlyTides[currentHour];
const nextHour = (currentHour + 1) % hourlyTides.length;
const nextTideHeight = hourlyTides[nextHour];
const isPushing = nextTideHeight > currentTideHeight;
const tideDirection = isPushing ? "Pushing" : "Pulling";
const swell = marineRes.data.current;