Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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