-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (49 loc) · 1.64 KB
/
app.js
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
42
43
44
45
46
47
48
49
50
51
52
53
const yargs = require("yargs");
const geocode = require("./geocode/geocode");
const weather = require("./weather/weather");
//Setting up yargs for input
const argv = yargs
.options({
a: {
demand: true,
alias: 'address',
describe: 'Address to fetch weather for',
//make sures that it parses through it as a string and not anything else
string: true
}
})
.help()
.alias('help', 'h')
.argv;
//PROMISES METHODS
geocode.geocodeAddress(argv.a)
.then(results => {
console.log("address: ", results.address);
return weather.getWeather(results.latitude, results.longitude);
})
.then(weatherResults => {
console.log(`it's currently ${weatherResults.temperature} farenheit. It feels like ${weatherResults.apparentTemperature} farenheit.`);
})
.catch(errorMessage => {
console.log(errorMessage);
});
//CALLBACK METHOD
// geocode.geocodeAddress(argv.a, (errorMessage, results) => {
// if (errorMessage) {
// console.log(errorMessage);
// } else {
// //the second argument is useless ignore it
// // the third argument is number of indents per line or something
// // console.log(JSON.stringify(body, undefined, 2));
// // console.log(JSON.stringify(results, undefined, 2));
// weather.getWeather(results.latitude, results.longitude, (errorMessage, weatherResults) => {
// if (errorMessage) {
// console.log(errorMessage);
// } else {
// console.log("address: ", results.address);
// // console.log(JSON.stringify(weatherResults, undefined, 2));
// console.log(`it's currently ${weatherResults.temperature} farenheit. It feels like ${weatherResults.apparentTemperature} farenheit.`);
// }
// });
// }
// });