Skip to content

Instantly share code, notes, and snippets.

@owans
Last active April 17, 2019 17:27
Show Gist options
  • Save owans/0bc695cdf40131c358f6e9d36a0bdd4b to your computer and use it in GitHub Desktop.
Save owans/0bc695cdf40131c358f6e9d36a0bdd4b to your computer and use it in GitHub Desktop.
API for tomorrow's weather
const ora = require('ora');
const getWeather = require('../utils/weatherforecast');
const getLocation = require('../utils/location');
module.exports = async (args) => {
const spinner = ora().start();
try{
const location = args.location || args.l ||await getLocation();
const forecast = await getWeather(location);
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate()+1);
spinner.stop();
console.log(`Weather Conditions for ${tomorrow} in ${location.city}, ${location.country_code}:`);
console.log(`\t${forecast.forecast.forecastday[0].day.condition.text}, ${forecast.forecast.forecastday[0].day.maxtemp_c}F`);
}catch(error){
console.error(error);
}
}

const axios = require('axios');

module.exports = async (location) => { let result; try{ result = await axios({ method: 'GET', url: http://api.apixu.com/v1/forecast.json?key=5274a607cd064255b42175703191604&q=${location.city} }); }catch(error){ console.error(error); } return result.data; };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment