-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (52 loc) · 2.08 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
const custom = require('./custom.json');
const settings = require('./settings.json');
const timetable = require('@wulkanowy/timetable-parser');
const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');
var out = {}
let promises = [];
axios.get(`${settings.url}/lista.html`).then(response => {
var $ = cheerio.load(response.data);
var x = $("p > a")
for (let i = 0; i<x.length; i++) {
promises.push(axios.get(`${settings.url}/${$(x[i]).attr('href')}`))
}
}).then(function() {
axios.all(promises).then(axios.spread((...args) => {
for (let i = 0; i < args.length; i++) {
const table = new timetable.Table(args[i].data);
const lessons = table.getDays();
for (day = 0; day <= 4; day++) {
for (hour = 0; hour <= 9; hour++) {
if (!lessons[day][hour]) continue
lessons[day][hour].forEach(function(f) {
if (!f.teacher) {
custom.forEach(function(x) {
subregex = new RegExp(x.subregex)
roomregex = new RegExp(x.roomregex)
if (subregex.test(f.subject) && roomregex.test(f.room)) {
f.subject = x.subject
f.teacher = x.teacher
}
})
}
if (!out[f.teacher]) {
out[f.teacher] = new Array(5);
for (i = 0; i <= 4; i++) {
out[f.teacher][i] = new Array(10);
}
}
var test = {przedmiot: f.subject, sala: f.room};
out[f.teacher][day][hour] = test;
})
}
}
}
})).then(() => {
if (!fs.existsSync("static")) {
fs.mkdirSync("static");
}
fs.writeFileSync('./static/output.json', JSON.stringify(out))
})
})