-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget.js
133 lines (100 loc) · 3.24 KB
/
get.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
process.env.NTBA_FIX_319 = 1;
const TelegramBot = require('node-telegram-bot-api');
const puppeteer = require('puppeteer');
const fs = require('fs');
var config = require('./config.json');
var looksSame = require('looks-same');
(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
defaultViewport: null
// headless: false // For debug
});
const page = await browser.newPage();
await page.setViewport({width: 1920, height: 1920, deviceScaleFactor: 2});
// Gaps login
console.log("Load gaps login...")
await page.goto('https://gaps.heig-vd.ch/consultation/controlescontinus/consultation.php');
await page.waitForSelector('select[id="user_idp"]', {
visible: true,
});
console.log("Loaded !")
console.log("Select HES-SO")
await page.select('#user_idp', 'https://aai-logon.hes-so.ch/idp/shibboleth')
console.log("Click on connect button")
await page.click('#wayf_submit_button')
// AII login
console.log("Load page AAI login...")
await page.waitForSelector('button[id="login-button"]', {
visible: true,
});
console.log("Loaded !")
console.log("Filled the fields")
await page.type('#username', config.username);
await page.type('#password', config.password);
console.log("Click on connect HES-SO button")
await page.click('#login-button');
// Gaps grades
console.log("Load grades page...")
try {
await page.waitForSelector('td[class="titreBox"]', {
visible: true,
});
} catch (error) {
console.log("Error while loading grades page !")
console.log("Check your credentials !")
browser.close()
process.exit(0)
}
console.log("Loaded !")
console.log("Select semester")
await page.select('#selta', config.semester)
await new Promise(r => setTimeout(r, 200));
console.log("load grades...")
try {
await page.waitForSelector('table[class="displayArray"]', {
visible: true,
});
} catch (error) {
console.log("Error while loading grades")
browser.close()
process.exit(0)
}
console.log("Grades loaded !")
console.log("Save HTML to image")
grades = await page.$('table[class="displayArray"]');
try {
await grades.screenshot({
path: './notes.png'
});
} catch (e) {
console.log("error :" + e)
}
console.log("Saved !")
// Compare image
if (fs.existsSync('./old.png')) {
console.log("Compare with last time...")
await new Promise((resolve) => {
looksSame('./notes.png', './old.png', async function (error, { equal }) {
if (!equal) {
console.log("Different from last time!")
console.log("Send notification...")
const bot = new TelegramBot(config.telegram.token, { polling: true });
const photo = fs.createReadStream('./notes.png')
await bot.sendDocument(config.telegram.chatId, photo, { caption: "Il y a du changement" })
console.log("Sended!")
} else {
console.log("Same from last time!")
}
resolve()
})
})
} else {
console.log('First time use script! Nothing to compare!')
}
fs.rename('./notes.png', './old.png', () => {
console.log("Save current for next time!");
});
browser.close()
process.exit(0)
})();