-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
63 lines (51 loc) · 2.03 KB
/
main.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
const readline = require('readline');
const fs = require('fs');
const extractData = require('./scrapeData.js');
const processData = require('./createStats/statsProcessing.js');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.clear();
console.log('\nAnimePlanet-Stats-Visualizer');
console.log('The program is in progress but hopefully you still enjoy it :p \n');
rl.question('Enter your username: ', (username) => {
askType();
function askType() {
rl.question('Type "anime" or "manga": ', async (type) => {
if (type.toLowerCase() === 'anime' || type.toLowerCase() === 'manga') {
askSkipScraping(type);
} else {
console.log('Invalid input. Type "anime" or "manga".');
askType();
}
});
}
function askSkipScraping(type) {
rl.question('Do you want to skip scraping? (y/n): ', async (skip) => {
try {
const skipScraping = skip.toLowerCase() === 'y' ? true : false;
if (skipScraping) {
const jsonData = fs.readFileSync('dataJson.json', 'utf8');
if (jsonData) {
const parsedData = JSON.parse(jsonData);
if (parsedData.length > 0) {
const dataType = parsedData[0].dataType;
if (dataType !== type.toLowerCase()) {
throw new Error(`Data type in JSON (${dataType}) doesn't match the provided type (${type.toLowerCase()}).`);
}
}
}
}
console.log('Starting to scrape.');
await extractData(username, type, skipScraping);
console.log("Processing data...");
processData();
rl.close();
} catch (error) {
console.error('An error occurred:', error);
rl.close();
}
});
}
});