From 0804c0aa74e2f3d051785d5b245f3995a008fcce Mon Sep 17 00:00:00 2001 From: GeorgeWebberley Date: Wed, 28 Jan 2026 12:22:12 +0100 Subject: [PATCH] Fixed script for tidal data --- fetcher/index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fetcher/index.js b/fetcher/index.js index a810aba..c9b789f 100644 --- a/fetcher/index.js +++ b/fetcher/index.js @@ -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}¤t=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}¤t=swell_wave_height,swell_wave_period,swell_wave_direction&hourly=sealevel`; const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=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;