From 8363fd950a8535d79e4bc799209969f9d7ed3091 Mon Sep 17 00:00:00 2001 From: pswsm Date: Tue, 7 Feb 2023 19:08:44 +0100 Subject: [PATCH] More testing --- src/routes/openmeteo/+page.server.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes/openmeteo/+page.server.ts b/src/routes/openmeteo/+page.server.ts index 476f98f..c2c2326 100644 --- a/src/routes/openmeteo/+page.server.ts +++ b/src/routes/openmeteo/+page.server.ts @@ -1,14 +1,15 @@ const geocodingApiBase: string = "https://geocoding-api.open-meteo.com/v1/search"; const openMeteoApiBase: string = "https://api.open-meteo.com/v1/forecast"; let location: string = "L'Hospitalet de Llobregat"; -let previousLocation = ''; +let previousLocation: string = ''; export function load(): object { let openMeteoData = getFromOpenMeteo(location); - let latitude: number = openMeteoData.then((data) => data.results[0].latitude); - let longitude: number = openMeteoData.then((data) => data.results[0].longitude); + let latitude: Promise = openMeteoData.then((data) => data.results[0].latitude).catch((_e) => 41.35967); + let longitude: Promise = openMeteoData.then((data) => data.results[0].longitude).catch((_e) => 2.10028 ); let openMeteoWeather = getWeatherFromOpenMeteo(latitude, longitude); - return { location: openMeteoData.then( (data) => data.results[0].name ).catch( (_e) => previousLocation ), weatherData: openMeteoWeather, latitude, longitude } + let openMeteoFetchUrl: string = openMeteoApiBase + '?latitude=' + latitude + '&logitude=' + longitude; + return { location: openMeteoData.then( (data) => data.results[0].name ).catch( (_e) => previousLocation ), weatherData: openMeteoWeather, latitude, longitude, openMeteoFetchUrl } }; function changeLocation(newLoc: string): void { @@ -29,6 +30,6 @@ async function getFromOpenMeteo(ubicacio: string): Promise { } async function getWeatherFromOpenMeteo(latitude: any, longitude: any) { - let openMeteoResponse: Response = await fetch(`${openMeteoApiBase}?latitude=12&longitude=12`); + let openMeteoResponse: Response = await fetch(openMeteoApiBase + '?latitude=' + latitude.toString() + '&logitude=' + longitude.toString()); return openMeteoResponse.json() }