-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (46 loc) · 1.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import dotenv from 'dotenv'
dotenv.config()
import { leerInput, inquirerMenu, pausa, listarLugares } from './helpers/inquirer.js';
import { Busquedas } from './models/busquedas.js';
const main = async() => {
const busquedas = new Busquedas();
let opt;
do {
opt = await inquirerMenu();
switch( opt ) {
case 1:
// Mostrar mensaje
const termino = await leerInput('Ciudad:');
// Buscar los lugares
const lugares = await busquedas.ciudad(termino);
// Seleccionar el lugar
const id = await listarLugares(lugares);
if ( id === '0' ) continue;
const lugarSel = lugares.find( l => l.id === id );
// Guardar en DB
busquedas.agregarHistorial( lugarSel.nombre );
// Clima
const clima = await busquedas.climaLugar( lugarSel.lat, lugarSel.lng );
// Mostrar resultados
console.clear();
console.log('\nInformación de la ciudad\n'.green);
console.log('Ciudad:', lugarSel.nombre.green);
console.log('Lat:', lugarSel.lat);
console.log('Lng:', lugarSel.lng);
console.log('Temperatura:', clima.temp);
console.log('Mínima:', clima.min);
console.log('Máxima:', clima.max);
console.log('Como está el clima:', clima.desc.green);
break;
case 2:
console.log('\nÚltimas búsquedas'.yellow);
busquedas.historialCapitalizado.forEach( (lugar, i) => {
const idx = `${ i + 1 }.`.green;
console.log( `${ idx } ${ lugar }` );
})
break;
}
if ( opt !== 0 ) await pausa();
} while (opt !== 0);
}
main();