-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetweather-from-api.js
35 lines (30 loc) · 970 Bytes
/
getweather-from-api.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
const yargs = require('yargs');
const request = require('request');
const getLatLng = require('./getLatLng');
const getTemp = require('./getTemp');
const argv = yargs
.command('get', 'Get weather from address', {
address: {
describe: 'Address where you want to know weather.',
demand: true,
type: 'string',
alias: 'a'
}
})
.help()
.argv ;
var addressEncoded = encodeURIComponent(argv.a);
const apiKey = 'AIzaSyB5h7TvGR60hL1Vm0eWuE43dsu3TNfixWU' ;
const url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' ;
const urlAddress = url+addressEncoded+'&key='+apiKey ;
//console.log(urlAddress);
console.log(argv.a);
getLatLng.getLatLng(urlAddress).then((res) => {
console.log(res);
return getTemp.getTemp(res.lat, res.lng);
}).then((res) => {
console.log('======================');
console.log(res);
}).catch((errMessage) => {
console.log(errMessage);
});