Skip to content
This repository has been archived by the owner on Sep 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from NicoMigueles/scrapeHistCons
Browse files Browse the repository at this point in the history
scrapeHistorialConsolidado: new feature
  • Loading branch information
nmigueles authored Jun 29, 2020
2 parents a7cce70 + 7415b84 commit f730770
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 12 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Tool to retrieve information from the SIGA FRBA UTN website.

- [Scrape Cursada](https://github.com/NicoMigueles/siga-scraper#scrape-cursada)
- [Scrape Notas](https://github.com/NicoMigueles/siga-scraper#scrape-notas)
- [Scrape Historial Consolidado](https://github.com/NicoMigueles/siga-scraper#scrape-historial-consolidado)

### Scrape Cursada

Expand Down Expand Up @@ -71,6 +72,56 @@ Returns:
];
```

### Scrape Historial Consolidado

```typescript
scrapeHistorialConsolidado() : Promise<RowEntry[]>,
```

Returns:
`RowEntry[]`

```typescript
// Response RowEntry example.

export interface Acta {
sede: string;
libro: string;
folio: string;
nota?: number;
}

export interface RowEntry {
tipo: string; // 'Cursada' | 'Final';
estado: string;
plan: string; // Nombre del plan, ejemplo O95A (civil) o K08 (sistemas).
courseId: string; // Id del curso interno del SIGA
nombre: string; // Nombre del curso
year: number; // Año de la cursada
periodo: string; // Identificador del periodo
fecha: string; // DD/MM/AAAA
acta: Acta | null;
}
/*
{
"tipo": "Final",
"estado": "Aprob",
"plan": "K08",
"courseId": "950701",
"nombre": "Álgebra y Geometría Analítica",
"year": 2018,
"periodo": "K08 Anual",
"fecha": "29/11/2018",
"acta": {
"sede": "FRBA",
"libro": "PR045",
"folio": "180",
"nota": 8
}
}
*/
```

## Examples

### QuickStart
Expand Down
57 changes: 46 additions & 11 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import errors from './constants/errors';
import rgbtohex from './helpers/rgbtohex';
import decomposeDate from './helpers/decomposeDate';

import { Course, Nota, Notas } from './interfaces';
import { Course, Nota, Notas, RowEntry, Acta } from './interfaces';

const isTest: boolean = process.env.NODE_ENV === 'test';

Expand Down Expand Up @@ -46,33 +46,68 @@ export = class sigaScraper {
this.isLogged = true;
}

static async scrapeHistorialConsolidado() {
// TODO: Response formatting and interfacing.
if (!this.isLogged) throw new Error(errors.loginRequiredErrorMessage);
static async scrapeHistorialConsolidado(): Promise<RowEntry[]> {
if (!this.isLogged && !isTest)
throw new Error(errors.loginRequiredErrorMessage);

const historialConsolidadoPageUrl =
'http://siga.frba.utn.edu.ar/alu/hist.do';
const testUrl = 'https://mock-siga-scraper.netlify.app/histcon.html';

return await this.cluster.execute(async ({ page }: { page: any }) => {
await page.goto(historialConsolidadoPageUrl);
await page.goto(isTest ? testUrl : historialConsolidadoPageUrl);

const subjects = await page.evaluate(
const rows: RowEntry[] = await page.evaluate(
() =>
[
...document.querySelectorAll(
'body > div.std-desktop > div.std-desktop-desktop > form > div > div > table > tbody > tr',
),
]
.map((e) => {
const row: string[] = [];
[...(e as HTMLElement).querySelectorAll('td')].forEach((b) =>
row.push(b.innerText),
const [
tipo,
estado,
plan,
courseId,
nombre,
year,
periodo,
fecha,
sede,
libro,
folio,
nota,
] = [...(e as HTMLElement).querySelectorAll('td')].map(
(b) => b.innerText,
);
return row;
let acta: Acta | null;
if (libro == 'sin firma / promovido' || !libro) {
acta = null;
} else {
acta = {
sede,
libro,
folio: folio,
nota: nota ? Number(nota) : undefined,
};
}
return {
tipo,
estado,
plan,
courseId,
nombre,
year: Number(year),
periodo,
fecha,
acta,
};
})
.slice(2), // get rid of the header of the table.
);
return subjects;

return rows;
});
}

Expand Down
19 changes: 19 additions & 0 deletions lib/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ export interface Notas {
name: string;
notas: Nota[];
}

export interface Acta {
sede: string;
libro: string;
folio: string;
nota?: number;
}

export interface RowEntry {
tipo: string; // 'Cursada' | 'Final';
estado: string;
plan: string; // Nombre del plan, ejemplo O95A (civil) o K08 (sistemas).
courseId: string; // Id del curso interno del SIGA
nombre: string; // Nombre del curso
year: number; // Año de la cursada
periodo: string; // Identificador del periodo
fecha: string | null; // DD/MM/AAAA
acta: Acta | null;
}
92 changes: 92 additions & 0 deletions lib/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sigaScraper from '..';
import { RowEntry } from '../interfaces';

describe('Scrape Cursada', () => {
test('Deberia devolver un array de con informacion acerca asignaturas.', async (done) => {
Expand Down Expand Up @@ -101,3 +102,94 @@ describe('Scrape Notas', () => {
}
}, 60000);
});

describe('Scrape Historial Consolidado', () => {
test('Deberia devolver un array de las filas del historial consolidado.', async (done) => {
try {
await sigaScraper.start();
const expected: RowEntry[] = [
{
tipo: 'Cursada',
estado: 'Aprob',
plan: 'K08',
courseId: '950701',
nombre: 'Álgebra y Geometría Analítica',
year: 2018,
periodo: 'K08 Anual',
fecha: '29/11/2018',
acta: {
sede: 'FRBA',
libro: 'XVIII070',
folio: '135',
},
},
{
tipo: 'Final',
estado: 'Aprob',
plan: 'K08',
courseId: '950701',
nombre: 'Álgebra y Geometría Analítica',
year: 2018,
periodo: 'K08 Anual',
fecha: '29/11/2018',
acta: {
sede: 'FRBA',
libro: 'PR045',
folio: '180',
nota: 8,
},
},
{
tipo: 'Cursada',
estado: '',
plan: 'K08',
courseId: '951601',
nombre: 'Sistemas de Representación',
year: 2018,
periodo: 'K08 Anual',
fecha: '',
acta: null,
},
{
tipo: 'Cursada',
estado: 'Aprob',
plan: 'K08',
courseId: '951601',
nombre: 'Sistemas de Representación',
year: 2018,
periodo: 'K08 Anual',
fecha: '29/11/2018',
acta: null,
},
{
tipo: 'Final',
estado: 'Aprob',
plan: 'K08',
courseId: '951601',
nombre: 'Sistemas de Representación',
year: 2018,
periodo: 'K08 Sin Cursar',
fecha: '29/11/2018',
acta: {
sede: 'FRBA',
libro: 'PR046',
folio: '68',
nota: 9,
},
},
];
const scrapeResponse: RowEntry[] = await sigaScraper.scrapeHistorialConsolidado();

// console.log(JSON.stringify(scrapeResponse, null, 2));

expect(scrapeResponse instanceof Array).toBeTruthy();
expect(scrapeResponse).toEqual(expected);
done();
} catch (error) {
console.log(error);
done.fail(error);
} finally {
await sigaScraper.stop();
}
}, 60000);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siga-scraper",
"version": "1.2.1",
"version": "1.3.0",
"description": "Tool to scrape information from SIGA FRBA UTN.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit f730770

Please sign in to comment.