-
-
Save JonathanPicques/59191e2e7df2ef77391f57843d42543c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const city = celestoryPoints.get('city', 'Paris'); | |
const location = await fetch(`https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/search?query=${city}`); | |
const locationData = await location.json(); | |
if (locationData && locationData[0] && locationData[0].woeid) { | |
const woeid = locationData[0].woeid; | |
const weather = await fetch(`https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/${woeid}`); | |
const weatherData = await weather.json(); | |
if (weatherData && weatherData.consolidated_weather && weatherData.consolidated_weather.length > 0) { | |
celestoryPoints.set('city', city); | |
celestoryPoints.set('weather', weatherData.consolidated_weather[0].weather_state_name); | |
celestoryPoints.set('temperature', weatherData.consolidated_weather[0].the_temp); | |
return; | |
} | |
} | |
celestoryPoints.set('city', city); | |
celestoryPoints.set('weather', 'NOT_FOUND'); | |
celestoryPoints.set('temperature', 'NOT_FOUND'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment