Skip to content

Commit

Permalink
Primer comit
Browse files Browse the repository at this point in the history
  • Loading branch information
edelvallep committed Jul 20, 2019
0 parents commit 5d6d705
Show file tree
Hide file tree
Showing 244 changed files with 22,564 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const lugar = require('./lugar/lugar');
const clima = require('./clima/clima');

const argv = require('yargs').options({
direccion: {
alias: 'd',
desc: 'Direccion de la ciudad para obener el clima',
demand: true
}
}).argv;

//lugar.getLugarLatLng(argv.direccion).then(console.log);
//clima.getClima(40.750000, -74.000000).then(console.log);

const getInfo = async(direccion) => {

try {
const coordes = await lugar.getLugarLatLng(direccion);
const temp = await clima.getClima(coordes.lat, coordes.lng);
return `El clima de ${coordes.dir} es de ${temp}`
} catch (e) {
return `No se pudo determinar el clima de ${direccion}`
}

}

getInfo(argv.direccion)
.then(console.log)
.catch(console.log);
1 change: 1 addition & 0 deletions clima/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
6 changes: 6 additions & 0 deletions clima/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
##Aplicacion del clima - curso node

Recuerda ejecutar '''npm install''' para las librerias


## Ejemplo : node app -d "New York"
14 changes: 14 additions & 0 deletions clima/clima.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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=be4d5e9db9b5918cf282c5a9d1aebd35`)

return resp.data.main.temp;

}


module.exports = {
getClima
}
33 changes: 33 additions & 0 deletions lugar/lugar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const axios = require('axios');

const getLugarLatLng = async(direccion) => {

const encoudeURL = encodeURI(direccion);

const instance = axios.create({
baseURL: 'https://devru-latitude-longitude-find-v1.p.rapidapi.com/latlon.php?location=' + encoudeURL,
headers: { 'X-RapidAPI-Key': '9f7b574f86mshcf6b47f4bde626dp18db4bjsnedb3a25abaaf' }
});

const resp = await instance.get();

if (resp.data.Results.length === 0) {
throw new Error('No hay resultados para' + direccion);
}

const data = resp.data.Results[0];
const dir = data.name;
const lat = data.lat;
const lng = data.lon;

return {
dir,
lat,
lng
}

}

module.exports = {
getLugarLatLng
}
14 changes: 14 additions & 0 deletions node_modules/ansi-regex/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/ansi-regex/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions node_modules/ansi-regex/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions node_modules/ansi-regex/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d6d705

Please sign in to comment.