-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
94 lines (77 loc) · 3.1 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
// // console.log('starting')
// // setTimeout(() => {
// // console.log('0 sec timer')
// // },0)
// // setTimeout(() => {
// // console.log('2 sec timer')
// // },2000)
// // console.log('stopping')
// const request= require('request')
const geocode = require('./utilis/geocode')
const forecast= require('./utilis/forecast')
// const url='https://api.darksky.net/forecast/20797fd9bf3bf28d9c9b21657ffb10d3/37.8267,-122.4233?units=si&lang=es'
// request({url:url,json:true}, (error,response) =>{
// // console.log(response)
// // const data = JSON.parse(response.body)
// // console.log(data.currently)
// // console.log(response.body.currently)
// if(error){
// console.log('net not available')
// }
// else if(response.body.error ){
// console.log('unable to find location')
// }
// else{
// console.log(response.body.daily.data[0].summary + ' the temp is '+ response.body.currently.temperature + ' chances of rain ' + response.body.currently.precipProbability)
// }
// })
// const geocodeurl='https://api.mapbox.com/geocoding/v5/mapbox.places/Los%20Angeles.json?access_token=pk.eyJ1IjoidGFueWExNzAwIiwiYSI6ImNrODFzdThvZTAwNjYzb3F0dDJjNXdna3IifQ.1rzB88dTA8LP22mHMwBmow'
// request({ url:geocodeurl , json:true},(error, response) =>{
// if(error){
// console.log('net not available')
// }
// else if(response.body.features.length===0 ){
// console.log('unable to find location')
// }
// else{
// const lat=response.body.features[0].center[1]
// const long=response.body.features[0].center[0]
// console.log(lat,long)
// }
// })
// const geocode = (address, callback) => {
// const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + address + '.json?access_token=pk.eyJ1IjoiYW5kcmV3bWVhZDEiLCJhIjoiY2pvOG8ybW90MDFhazNxcn J4OTYydzJlOSJ9.njY7HvaalLEVhEOIghPTlw&limit=1'
// request({ url: url, json: true }, (error, response) => {
// if (error) {
// callback('Unable to connect to location services!', undefined)
// } else if (response.body.features.length === 0) {
// callback('Unable to find location. Try another search.', undefined)
// }
// else {
// callback(undefined, {
// latitude: response.body.features[0].center[0],
// longitude: response.body.features[0].center[1],
// location: response.body.features[0].place_name
// })
// }
// })
// }
const address=process.argv[2]
if(!address){
console.log('provide address')
}else{
geocode(address, (error, {latitude,longitude,location}) => {
if(error){
return console.log(error)
}
// console.log('Error', error)
// console.log('Data', data)
forecast(latitude,longitude, (error, forecastdata) => {
if(error){
return console.log(error)
}
console.log(location)
console.log(forecastdata)
})
})
}