File tree Expand file tree Collapse file tree 8 files changed +575
-0
lines changed Expand file tree Collapse file tree 8 files changed +575
-0
lines changed Original file line number Diff line number Diff line change
1
+ node_modules
Original file line number Diff line number Diff line change
1
+ ## Aplicacion del clima - Curso node
2
+
3
+ Recuerden ejecutar ``` npm install ``` para las librerias
4
+
5
+ ### Ejemplo:
6
+ ```
7
+ node app -d "Madrid"
8
+ ```
Original file line number Diff line number Diff line change
1
+ const lugar = require ( './lugar/lugar' ) ;
2
+ const clima = require ( './clima/clima' ) ;
3
+ const info = require ( './info/info' ) ;
4
+
5
+ const argv = require ( 'yargs' ) . options ( {
6
+ direccion : {
7
+ alias : 'd' ,
8
+ desc : 'Direcion de la cuidad a obtener el clima' ,
9
+ deman : true
10
+ }
11
+
12
+ } ) . argv ;
13
+
14
+ lugar . getLugarLatLong ( argv . direccion )
15
+ . then ( console . log ) ;
16
+
17
+
18
+ clima . getClima ( 35 , 139 )
19
+ . then ( console . log )
20
+ . catch ( console . log ) ;
21
+
22
+ info . getInfo ( argv . direccion )
23
+ . then ( console . log )
24
+ . catch ( console . log ) ;
Original file line number Diff line number Diff line change
1
+ const axios = require ( 'axios' ) ;
2
+
3
+ const getClima = async ( lat , lng ) => {
4
+
5
+ const resp = await axios . get ( `https://api.openweathermap.org/data/2.5/weather?lat=${ lat } &lon=${ lng } &APPID=edee8540d6d522f3e3c675d3b5fd38df&units=metric` )
6
+
7
+ return resp . data . main . temp ;
8
+
9
+ }
10
+
11
+ module . exports = {
12
+ getClima
13
+ }
Original file line number Diff line number Diff line change
1
+
2
+ const lugar = require ( '../lugar/lugar' ) ;
3
+ const clima = require ( '../clima/clima' ) ;
4
+
5
+ const getInfo = async ( direccion ) => {
6
+
7
+ try {
8
+ const coords = await lugar . getLugarLatLong ( direccion ) ;
9
+ const temp = await clima . getClima ( coords . lat , coords . lng ) ;
10
+ return console . log ( `El clima de ${ direccion } es de ${ temp } ` ) ;
11
+
12
+ } catch ( error ) {
13
+ throw new Error ( `No se pudo determinar el clima de ${ direccion } ` ) ;
14
+
15
+ }
16
+ }
17
+
18
+ module . exports = {
19
+ getInfo
20
+ }
Original file line number Diff line number Diff line change
1
+ const axios = require ( 'axios' ) ;
2
+
3
+ const getLugarLatLong = async ( dir ) => {
4
+
5
+ const encodedUrl = encodeURI ( dir ) ;
6
+
7
+ const instance = axios . create ( {
8
+ baseURL : `https://devru-latitude-longitude-find-v1.p.rapidapi.com/latlon.php?location=${ encodedUrl } ` ,
9
+ headers : { 'X-RapidAPI-Key' : '9878a58125mshaedb75df5ecb322p15df4djsnbd795bcd4d51' }
10
+ } ) ;
11
+
12
+ const resp = await instance . get ( ) ;
13
+ if ( resp . data . Results . length === 0 ) {
14
+ throw new Error ( `No hay resultados para ${ dir } ` ) ;
15
+ }
16
+
17
+ const data = resp . data . Results [ 0 ] ;
18
+ const direccion = data . name ;
19
+ const lat = data . lat ;
20
+ const lng = data . lon ;
21
+
22
+ return {
23
+ direccion,
24
+ lat,
25
+ lng
26
+ }
27
+ }
28
+
29
+ module . exports = {
30
+ getLugarLatLong
31
+ }
You can’t perform that action at this time.
0 commit comments