-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8f4b14d
Showing
13 changed files
with
2,187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
/src/apis | ||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const yargs = require('yargs'); | ||
const axios = require('axios'); | ||
|
||
const argv = yargs | ||
.options({ | ||
a:{ | ||
demand:true, | ||
alias: 'address', | ||
describe: 'Iveskite adresa, kad butu gaulima gauti orus', | ||
string:true | ||
} | ||
}) | ||
.help() | ||
.alias('help','h') | ||
.argv; | ||
|
||
const userAddress = argv.address; | ||
|
||
var encodedValue = encodeURIComponent(userAddress); | ||
var geocodeURL = `https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDaHcZvSyInIGROtyZ6i37hPBlI-qZhSQc&address=${encodedValue}`; | ||
|
||
axios.get(geocodeURL).then((response) =>{ | ||
if(response.data.status === 'ZERO_RESULTS'){ | ||
throw new Error('Unable to find that adress'); | ||
} else { | ||
var lat = response.data.results[0].geometry.location.lat; | ||
var lng = response.data.results[0].geometry.location.lng; | ||
var weatherURL = `https://api.darksky.net/forecast/cf3a775bc1585bdc5dcd0259f6df0ca7/${lat},${lng}`; | ||
console.log('Adress: ',response.data.results[0].formatted_address); | ||
return axios.get(weatherURL); | ||
} | ||
}).then(response => { | ||
var temperature = response.data.currently.temperature; | ||
var actualTemperature = response.data.currently.apparentTemperature; | ||
console.log('Temperature:' , Math.floor((temperature -32) * 5/9)); | ||
console.log('Feels like:', Math.floor((actualTemperature - 32) * 5/9)); | ||
}) | ||
.catch(error => { | ||
if(error.code === 'ENOTFOUND'){ | ||
console.log('Unable to connect to API servers') | ||
} else{ | ||
console.log(error.message); | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const yargs = require('yargs'); | ||
const geocode = require('./geocode/geocode'); | ||
const weather = require('./weather/weather'); | ||
|
||
const argv = yargs | ||
.options({ | ||
a:{ | ||
demand:true, | ||
alias: 'address', | ||
describe: 'Iveskite adresa, kad butu gaulima gauti orus', | ||
string:true | ||
} | ||
}) | ||
.help() | ||
.alias('help','h') | ||
.argv; | ||
|
||
const userAddress = argv.address; | ||
|
||
geocode.geocodeAddress(userAddress, (errorMessage, results) =>{ | ||
if(errorMessage){ | ||
console.log(errorMessage); | ||
} else { | ||
//console.log(JSON.stringify(results, undefined, 2)); | ||
console.log(`Address:${results.address}\n`); | ||
weather.getWeather(results.lat,results.lng,(errorMessage, results)=>{ | ||
if(errorMessage){ | ||
console.log(errorMessage); | ||
} else{ | ||
console.log(`Temperature: ${results.temperature}`); | ||
console.log(`Sensitive temperature: ${results.fellingTemperature}`); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const request = require('request'); | ||
|
||
const geocodeAddress = (address, callback) =>{ | ||
var encodedValue = encodeURIComponent(address); | ||
|
||
//Reikia, kad vartotojas ivestu Geguziu 73 Siauliai | ||
|
||
request({ | ||
url:`https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDaHcZvSyInIGROtyZ6i37hPBlI-qZhSQc&address=${encodedValue}`, | ||
json: true | ||
},(error, response, body)=>{ | ||
if(error){ | ||
callback('Unable to connect to Google servers'); | ||
} else if(body.status === 'ZERO_RESULTS'){ | ||
callback('Unable to find that address'); | ||
} else if(body.status === 'OK'){ | ||
callback(undefined,{ | ||
address:body.results[0].formatted_address, | ||
lat:body.results[0].geometry.location.lat, | ||
lng:body.results[0].geometry.location.lng | ||
}); | ||
// console.log(`Address: ${body.results[0].formatted_address}\n`); | ||
// console.log(`Latitude: ${body.results[0].geometry.location.lat}`); | ||
// console.log(`Longitude: ${body.results[0].geometry.location.lng}`); | ||
} | ||
// console.log(`Address: ${body.results[0].locations[0].street}, ${body.results[0].locations[0].adminArea3},${body.results[0].locations[0].adminArea1}\n`); | ||
// console.log(`Latitude: ${body.results[0].locations[0].latLng.lat}`); | ||
// console.log(`Longitude: ${body.results[0].locations[0].latLng.lng}`); | ||
}); | ||
}; | ||
|
||
module.exports.geocodeAddress = geocodeAddress; |
Oops, something went wrong.