-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (53 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
63
64
65
66
require("dotenv").config();
const {
leerInput,
inquirerMenu,
pausa,
listadoDeLugares,
} = require("./helpers/inquirer");
const Busquedas = require("./models/busqueda");
console.log("hola gente soy lolito");
const main = async () => {
const busquedas = new Busquedas();
let opt;
do {
opt = await inquirerMenu();
switch (opt) {
case 1:
//Mostrar mensaje
const lugar = await leerInput("Ciudad: ");
//Buscar lugares con coincidencias
const lugares = await busquedas.ciudad(lugar);
//seleccionar el lugar
const id = await listadoDeLugares(lugares);
if(id === '0') continue;
const selectPlace = lugares.find((lugar) => lugar.id === id);
//guardar en db el lugar
busquedas.agregarHistorial(selectPlace.nombre);
const { nombre, latitud, longitud } = selectPlace;
//clima
const clima = await busquedas.climaCiudad(latitud, longitud);
const { desc, temperatura, temp_max, temp_min } = clima;
console.clear();
console.log("\n============================".red);
console.log(" Información de la ciudad".red);
console.log("============================\n".red);
console.log("Ciudad: ", nombre.green);
console.log("Longitud: ", longitud);
console.log("Latitutd: ", latitud);
console.log("Descripción del clima:", desc.green);
console.log("Temperatura: ", temperatura, "ºC");
console.log("Minima: ", temp_min, "ºC");
console.log("Maxima: ", temp_max, "ºC");
break;
case 2:
busquedas.historialCapitalize.forEach( (lugar, i) => {
const idx = `${ i + 1}.`.green;
console.log( `${ idx } ${lugar}`.white );
} )
break;
}
if (opt !== 0) await pausa();
} while (opt !== 0);
};
main();