forked from vaarigupta/Weather-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
134 lines (68 loc) · 2.16 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const request = require('request');
const yargs = require('yargs');
const geocode = require('./geocode/geocode.js');
const weather = require('./weather/weather.js');
const argv = yargs
.options({
a :
{
alias:'address',
demand : true,
describe:'finding location for the given address'
}
}
).alias('h','help')
.argv;
//console.log(argv);
//console.log(process)
geocode.geocodeAddress(argv.a,(errorMessage ,result)=>{
if(errorMessage)
{
console.log(errorMessage);
}
if(result)
{
var long = result.longitude;
var lat = result.latitude;
weather.getWeather(long,lat,(errorMessage,weatherResults)=>{
if(errorMessage)
{
console.log(errorMessage);
}
else
{ console.log(`Location : ${result.address}`)
console.log(`It's temperature is ${weatherResults.temperature} but it feels like ${weatherResults.apparentTemp}`)
}
});
}
});
//api key - 5da9efc326a46e965bedb46e9744fae6
// var encodedURL = encodeURIComponent(argv.a)
// request({
// // url : "https://maps.googleapis.com/maps/api/geocode/json?address="+encodeURIComponent(argv.a),
// url : `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedURL}`,
// json : true
// },(error,response , body)=>{
// //console.log('error:', error); // Print the error if one occurred
// //console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
// //console.log(body)
// if(error)
// {
// console.log("Oops !! Unable to connect with google server ");
// console.log("please Check URL or your internet connection");
// }
// else if(body.status === 'ZERO_RESULTS')
// {
// console.log("Oops !! Unable to find location for this address")
// }
// else if(body.status==='OK')
// {
// console.log(`Address : ${body.results[0].formatted_address}`); // Print the HTML for the Google homepage.
// console.log(`Longitude : ${body.results[0].geometry.location.lat}`);
// console.log(`Latitude : ${body.results[0].geometry.location.lng}`);
// }
// else
// {
// console.log("Oops!!!!!!!!!!");
// }
// })