-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
71 lines (59 loc) · 2.24 KB
/
cli.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
67
68
69
70
71
// This file is the CLI implementation of the load shedding api
const readline = require('node:readline');
const { stdin: input, stdout: output } = require('node:process');
// const loadSheddingMap = require('./data/loadshedding-map.json');
const blocks = require('./data/blocks.json');
const { findCity, findSuburb } = require('./searchFunctions');
const { getUpcomingLoadSheddingSchedule } = require('./loadSheddingFunctions');
const { extractCities, extractSuburbs } = require('./spreadSheet');
const rl = readline.createInterface({ input, output });
const getUserProvince = async () => {
try {
return new Promise(resolve => {
rl.question('Which province do you live in?: ', provinceName => {
resolve('KwaZulu-Natal');
});
})
} catch (error) {
console.log(`ERROR:`, error);
}
}
const getUserCity = async () => {
try {
return new Promise(resolve => {
rl.question('Which city do you live in?: ', cityName => {
resolve('newcastle');
});
})
} catch (error) {
console.log(`ERROR:`, error);
}
}
const getUserSuburb = async () => {
try {
return new Promise(resolve => {
rl.question('Which suburb do you live in?: ', suburbName => {
resolve('osizweni');
});
})
} catch (error) {
console.log(`ERROR:`, error);
}
}
const main = async () => {
const provinceName = await getUserProvince();
const cityName = await getUserCity();
const suburbName = await getUserSuburb();
rl.close();
const myBlock = 8;
const cityList = extractCities();
const city = findCity(cityList, cityName);
const suburbList = extractSuburbs();
const suburb = findSuburb(suburbList, suburbName, city).filter(suburb => suburb['BLOCK'] === myBlock);
const blockSchedule = blocks.find(block => block['blockNumber'] === suburb[suburb.length - 1]['BLOCK']);
// console.log(blockSchedule['schedule']);
const upcomingLoadShedding = getUpcomingLoadSheddingSchedule(blockSchedule['schedule']);
// console.log(upcomingLoadShedding[0]['schedule'].filter(dailySchedule => dailySchedule.stage <= 2));
console.log(upcomingLoadShedding);
}
main();