-
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 c3a93fd
Showing
6 changed files
with
283 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 @@ | ||
node_modules/ |
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,11 @@ | ||
## Aplicación del clima en NodeJS utilizando OpenWeatherMap API | ||
|
||
Ejecutar ```npm install``` para instalar los paquetes necesarios. | ||
|
||
El API key no está incluida, pueden obtener una API key en [OpenWeather](https://openweathermap.org/) y reemplazarla | ||
en el archivo api.js | ||
|
||
### Ejemplo: | ||
``` | ||
node app -d "Ciudad de Mexico" | ||
``` |
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,18 @@ | ||
const weather = require('./weather/api'); | ||
const argv = require('yargs').options({ | ||
direccion: { | ||
alias: 'd', | ||
demand: true, | ||
desc: 'Dirección de la ciudad para obtener el clima' | ||
} | ||
}).argv; | ||
|
||
const loc = argv.direccion; | ||
|
||
weather.getWeather(loc).then(data => { | ||
if (data.data.cod == 200) { | ||
console.log(`El clima de ${loc} es de ${data.data.main.temp}`); | ||
} | ||
}).catch(e => { | ||
console.log(`Error, la ciudad no existe`); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
{ | ||
"name": "weather--app", | ||
"version": "1.0.0", | ||
"description": "Aplicación del clima", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Oscar Reyes", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"yargs": "^15.3.1" | ||
} | ||
} |
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,11 @@ | ||
const axios = require('axios').default; | ||
|
||
const apiKey = 'your-api-key-here-xxxxxxxxxxxxxx'; | ||
|
||
const getWeather = async(city) => { | ||
return await axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`); | ||
} | ||
|
||
module.exports = { | ||
getWeather | ||
} |