diff --git a/MagicMirror b/MagicMirror new file mode 160000 index 0000000000..118e21238c --- /dev/null +++ b/MagicMirror @@ -0,0 +1 @@ +Subproject commit 118e21238c3a9429092429dd6609a77feb5c4093 diff --git a/modules/default/weather/providers/metoffice.js b/modules/default/weather/providers/metoffice.js new file mode 100644 index 0000000000..e93ccbbeb1 --- /dev/null +++ b/modules/default/weather/providers/metoffice.js @@ -0,0 +1,48 @@ +// Update the base URL for the Met Office API +const baseURL = 'https://api-metoffice.new-endpoint.com/' + +// Function to fetch current weather data +function fetchCurrentWeather() { + const url = `${baseURL}/current?location=${this.config.location}&appid=${this.config.apiKey}`; + + url.searchParams.append('location', this.config.location); + url.searchParams.append('appid', this.config.apiKey); + + // Using fetch to make the API call + fetch(url) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok ' + response.statusText); + } + return response.json(); // Convert the response body to JSON + }) + .then(data => { + this.processWeatherData(data); + }) + .catch(error => { + // Handle any errors that occurred during the fetch + console.error('Unable to fetch Met Office weather data:', error); + });etch(url) + + +} + +function processWeatherData(data) { + + if (data && data.temperature && data.conditions && data.wind) { + + const currentTemperature = data.temperature.value; + const weatherConditions = data.conditions[0].description; + const windSpeed = data.wind.speed; + + const temperatureCelsius = currentTemperature - 273.15; + + console.log(`Current Temperature: ${temperatureCelsius.toFixed(1)}°C`); + console.log(`Weather Conditions: ${weatherConditions}`); + console.log(`Wind Speed: ${windSpeed} m/s`); + + + } else { + console.error("Unexpected API response structure:", data); + } +} \ No newline at end of file