Skip to content

Instantly share code, notes, and snippets.

@JonathanPicques
Created July 13, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanPicques/59191e2e7df2ef77391f57843d42543c to your computer and use it in GitHub Desktop.
Save JonathanPicques/59191e2e7df2ef77391f57843d42543c to your computer and use it in GitHub Desktop.
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