-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (51 loc) · 1.83 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
62
require('dotenv').config();
const {
leerInput,
inquirerMenu,
pausa,
listarLugares,
climaLugar,
} = require('./helpers/inquirer');
const Busquedas = require('./models/busquedas');
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 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);
busquedas.agregarHistorial(lugarSel.nombre.toLowerCase());
const temp = await busquedas.climaLugar(
lugarSel.lat,
lugarSel.lng
);
//Clima
//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: ', temp.temp);
console.log('Mínima:', temp.min);
console.log('Máxima:', temp.max);
console.log('Como está el clima: ', temp.desc.green);
break;
case 2:
busquedas.historialCapitalizado.forEach((lugar, i) => {
const idx = `${i + 1}.`.green;
console.log(`${idx} ${lugar} `);
});
}
if (opt !== 0) await pausa();
} while (opt !== 0);
};
main();