-
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
UBEIMAR ALVAREZ HERNANDEZ
authored and
UBEIMAR ALVAREZ HERNANDEZ
committed
Jul 11, 2019
0 parents
commit c72450f
Showing
7 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,10 @@ | ||
## Aplicación del Clima - Curso Node | ||
|
||
|
||
Recuerden ejecutar ```npm install``` para las librerías | ||
|
||
|
||
### Ejemplo: | ||
``` | ||
node app -d "San Jose Costa Rica" | ||
``` |
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,41 @@ | ||
|
||
|
||
const lugar = require('./lugar/lugar'); | ||
const clima = require('./clima/clima'); | ||
|
||
|
||
const argv = require('yargs').options({ | ||
direccion: { | ||
alias: 'd', | ||
desc: 'Dirección de la ciudad para obtener el clima', | ||
demand: true | ||
} | ||
}).argv; | ||
|
||
|
||
// lugar.getLugarLatLng( argv.direccion ) | ||
// .then( console.log ); | ||
|
||
// clima.getClima( 40.750000, -74.000000 ) | ||
// .then( console.log ) | ||
// .catch( console.log ); | ||
|
||
|
||
const getInfo = async( direccion ) => { | ||
|
||
|
||
try { | ||
const coords = await lugar.getLugarLatLng( direccion ); | ||
const temp = await clima.getClima( coords.lat, coords.lng ); | ||
return `El clima de ${ coords.direccion } es de ${ temp }.`; | ||
} catch (e) { | ||
return `No se pudo determinar el clima de ${ direccion }`; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
getInfo( argv.direccion ) | ||
.then( console.log ) | ||
.catch( console.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,16 @@ | ||
const axios = require('axios'); | ||
|
||
|
||
|
||
const getClima = async ( lat, lng ) => { | ||
|
||
const resp = await axios.get(`https://api.openweathermap.org/data/2.5/weather?lat=${ lat }&lon=${ lng }&appid=32f843d833c38373032f825c4a92418a&units=metric`) | ||
|
||
return resp.data.main.temp; | ||
|
||
} | ||
|
||
|
||
module.exports = { | ||
getClima | ||
} |
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,36 @@ | ||
const axios = require('axios'); | ||
|
||
|
||
const getLugarLatLng = async( dir ) => { | ||
|
||
const encodedUlr = encodeURI( dir ); | ||
|
||
const instance = axios.create({ | ||
baseURL: `https://devru-latitude-longitude-find-v1.p.rapidapi.com/latlon.php?location=${ encodedUlr }`, | ||
headers: {'X-RapidAPI-Key': 'YrIv9XHJxmmshCBitpg1YTAnahQSp1KbdHhjsnSBU1hvMDMlzK'} | ||
}); | ||
|
||
const resp = await instance.get(); | ||
|
||
if ( resp.data.Results.length === 0 ) { | ||
throw new Error(`No hay resultados para ${ dir }`); | ||
} | ||
|
||
const data = resp.data.Results[0]; | ||
const direccion = data.name; | ||
const lat = data.lat; | ||
const lng = data.lon; | ||
|
||
|
||
return { | ||
direccion, | ||
lat, | ||
lng | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
getLugarLatLng | ||
} | ||
|
Oops, something went wrong.