-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (39 loc) · 1.23 KB
/
app.js
File metadata and controls
41 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const yargs = require('yargs');
const geocode = require('./geocode/geocode.js');
const weather = require('./weather/weather.js');
//get the address from user input
const argv = yargs
.options({
a:{
demand:true,
alias:'address',
descrbibe:'Addres to fecth'
}
})
.help()
.alias('help','h')
.argv;
//call geocodeAddress and pass the address
geocode.geocodeAddress(argv.address ,(errorMessage, results) => {
//check the callback if we have error message else print the returned results
if(errorMessage)
{
console.log(errorMessage);
}
else {
//console.log(JSON.stringify(results, undefined, 2));
console.log(results.Address);
//call the getweather function and pass the longitude, lagitude
weather.getweather(results.Latitude,results.Longitude ,(errorMessage, weatherResults) => {
//check the callback if we have error message else print the returned results
if(errorMessage)
{
console.log(errorMessage);
}
else {
console.log(JSON.stringify(weatherResults, undefined, 2));
//console.log(`It's currently ${weatherResults.temperature}. It feels like ${weatherResults.apparentTemperature} :)`)
}
});
}
});