Last active
April 17, 2019 18:38
-
-
Save Israel025/07a41756c981c5f3e9eda5dfc093c84d to your computer and use it in GitHub Desktop.
weahter-cli application
This file contains hidden or 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 ora = require('ora'); | |
const getWeather = require('../utils/weather'); | |
const getLocation = require('../utils/location'); | |
module.exports = async (args) => { | |
const spinner = ora().start(); | |
try{ | |
const location = args.location || args.l || await getLocation(); | |
const weather = await getWeather(location); | |
spinner.stop(); | |
// console.log(weather); | |
console.log(`The condition for Tomorrow ${weather.list[1].dt_txt} in ${weather.city.name}, ${weather.city.country} is:`); | |
console.log(`\t${weather.list[1].main.temp}F`); | |
}catch(error){ | |
console.error(error); | |
} | |
} |
This file contains hidden or 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 axios = require('axios'); | |
module.exports = async (location) => { | |
let result; | |
try { | |
result = await axios({ | |
method: 'get', | |
url: `http://api.openweathermap.org/data/2.5/forecast?q=${location.city},${location.country_code}&APPID=6ea8e158302271fd6d95f5cfbf3a60e8&cnt=2`, | |
}) | |
} 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