-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (51 loc) · 1.42 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
import getBooks from "./books.js";
import getAndQueryCategories from "./categories.js";
import readline from "readline-sync";
function showMenu() {
console.log(`
Menú:
1. scrappear libros relacionados
2. scrappear categorias
3. Salir
Por favor, selecciona una opción: `);
}
async function handleOption(option) {
switch (option) {
case "1":
const url = readline.question(
`
Ej: "https://es.singlelogin.re/users/zrecommended#959363"
Ingresa la url que recomienda los libros: `
);
await getBooks(url);
break;
case "2":
const conf = readline.question(
`El scrapping de categorias solo debe realizarlo una vez, presione 's' para continuar: `
);
if (conf.trim().toLowerCase() === "s") {
await getAndQueryCategories();
} else {
console.log("No se realizará el scrapping de categorías.");
}
break;
case "3":
console.log("Saliendo...");
return false;
default:
console.log("Opción no válida. Por favor, intenta nuevamente.");
break;
}
let cotinue = readline.question("¿Deseas continuar? (s/n): ");
if (cotinue.trim().toLowerCase() != "s") return false;
return true;
}
async function main() {
let running = true;
while (running) {
showMenu();
const option = readline.question("Selecciona una opción: ");
running = await handleOption(option);
}
}
main();