siga-checker
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
const { chromium } = require('playwright');
|
||||
const fs = require('fs');
|
||||
|
||||
(async () => {
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: true
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
try {
|
||||
|
||||
console.log('1. A abrir SIGA...');
|
||||
|
||||
await page.goto('https://siga.edubox.pt/', {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 60000
|
||||
});
|
||||
|
||||
console.log('2. Login...');
|
||||
|
||||
await page.locator('#ion-input-0').fill(process.env.SIGA_USER);
|
||||
await page.locator('#ion-input-1').fill(process.env.SIGA_PASSWORD);
|
||||
|
||||
await page.locator('#ion-input-1').press('Enter');
|
||||
|
||||
console.log('3. A aguardar dashboard...');
|
||||
|
||||
await page.waitForURL('**/webapp/dashboard', {
|
||||
timeout: 60000
|
||||
});
|
||||
|
||||
await page.locator('custom-avatar-card').first().waitFor({
|
||||
state: 'visible',
|
||||
timeout: 30000
|
||||
});
|
||||
|
||||
console.log('4. A obter saldos...');
|
||||
|
||||
const alunos = await page.locator('custom-avatar-card').evaluateAll(cards => {
|
||||
|
||||
return cards.map(card => {
|
||||
|
||||
const nome =
|
||||
card.querySelector('.user-name')
|
||||
?.textContent
|
||||
?.trim();
|
||||
|
||||
const saldoTexto =
|
||||
card.querySelector(
|
||||
'.municipio-saldo .saldo-value ion-badge'
|
||||
)
|
||||
?.textContent
|
||||
?.trim();
|
||||
|
||||
const saldo = saldoTexto
|
||||
? parseFloat(
|
||||
saldoTexto
|
||||
.replace('€', '')
|
||||
.replace(/\s/g, '')
|
||||
.replace(',', '.')
|
||||
)
|
||||
: null;
|
||||
|
||||
return {
|
||||
nome,
|
||||
saldo
|
||||
};
|
||||
|
||||
}).filter(a => a.nome);
|
||||
|
||||
});
|
||||
|
||||
const agora = new Date();
|
||||
|
||||
const resultado = {
|
||||
atualizado: agora.toISOString(),
|
||||
alunos
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
'/app/siga-saldos.json',
|
||||
JSON.stringify(resultado, null, 2),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
console.log('\n========== SALDOS ==========');
|
||||
|
||||
alunos.forEach(aluno => {
|
||||
console.log(
|
||||
`${aluno.nome}: ${aluno.saldo?.toFixed(2)} €`
|
||||
);
|
||||
});
|
||||
|
||||
console.log('============================');
|
||||
|
||||
console.log('\nJSON criado:');
|
||||
console.log('/app/siga-saldos.json');
|
||||
|
||||
} catch (error) {
|
||||
|
||||
console.error('\nERRO:', error.message);
|
||||
process.exitCode = 1;
|
||||
|
||||
} finally {
|
||||
|
||||
await browser.close();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user