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 #3 from NicoMigueles/method-diff
Browse files Browse the repository at this point in the history
Diferenciación de métodos
  • Loading branch information
nmigueles authored Jun 29, 2020
2 parents 6afaccf + cb49768 commit c59dca1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Tool to retrieve information from the SIGA FRBA UTN website.

`npm i siga-scraper`


## Methods

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

Expand All @@ -34,16 +34,10 @@ Returns:
curso: string, // Código del curso, ejemplo: K1021
nombre: string, // Nombre del curso
color: string, // Color del curso
notas: [
{
instancia: string, // Instancia de evaluación
calificacion: number, // Nota, 0..10, el 0 representa el ausente.
},
],
dia: number, // Representación numérica de la semana.
hora: string, // Hora de la clase.
horaT: string, // Hora de finalización de la clase.
turno: Turno, // enum('Mañana', 'Tarde', 'Noche')
turno: string, // 'Mañana' | 'Tarde' | 'Noche'
aula: string, // Aula del curso.
sede: string, // Sede en la que se dicta el curso.
},
Expand All @@ -62,11 +56,14 @@ Returns:
```typescript
// Response example.
[
name: 'Análisis Matemático I',
[{
instancia: string,
calificacion: number,
}],
courseId: string, // Id del curso interno del SIGA
name: string, // 'Análisis Matemático I'
notas: [
{
instancia: string, // Instancia de evaluación
calificacion: number, // Nota, 0..10, el 0 representa el ausente.
}
],
];
```

Expand All @@ -84,7 +81,20 @@ async function main() {
const response = await sigaScraper.scrapeCursada();

console.log(response);

/*
[{
courseId: '950703',
curso: 'Z2004',
nombre: 'Análisis Matemático II',
aula: '115',
sede: 'Campus',
color: '#7A94CF',
turno: 'Mañana',
dia: 3,
hora: '8:30',
horaT: '12:30',
}, ...]
*/
await sigaScraper.stop();
}

Expand All @@ -97,8 +107,8 @@ main();
import sigaScraper from 'siga-scraper';

async function main() {
await sigaScraper.start(); // Inicia el cluster de navegadores que realizan el scrape.
await sigaScraper.login(SIGA_USER, SIGA_PASS); // Logea y guarda la session en el cluster.
await sigaScraper.start();
await sigaScraper.login(SIGA_USER, SIGA_PASS);
const tasksPromises = [
sigaScraper.scrapeNotas(),
sigaScraper.scrapeCursada(),
Expand Down
13 changes: 6 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export = class sigaScraper {
aula,
sede,
color: rgbtohex(color),
notas: [],
turno: shift[turno],
dia: dias.length > 1 ? dias : dias[0],
hora: horas.length > 1 ? horas : horas[0],
Expand Down Expand Up @@ -168,20 +167,20 @@ export = class sigaScraper {
'tbody > tr > td > span:nth-child(1) > a',
),
].map((e, i) => {
const name = `${
(e as HTMLElement).onclick!.toString().split(`'`)[5]
}`;
const onclickData = (e as HTMLElement).onclick!.toString().split(`'`);
const courseId = onclickData[3];
const name = onclickData[5];
const selector = `tbody > tr:nth-child(${
2 * i + 3
}) > td > span:nth-child(2) > a`;
return { name, selector };
return { courseId, name, selector };
}),
);

const response = [];
// Por cada asignatura, buscar las notas.
for await (const subject of subjects) {
const { name, selector } = subject;
const { courseId, name, selector } = subject;

await Promise.all([page.click(selector), page.waitForNavigation()]);

Expand Down Expand Up @@ -220,7 +219,7 @@ export = class sigaScraper {
}),
]);

response.push({ name, notas });
response.push({ courseId, name, notas });
}
return response;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export interface Course {
curso: string;
nombre: string;
color: string;
notas: [];
dia: number | number[];
hora: string | string[];
horaT: string | string[];
Expand All @@ -17,6 +16,7 @@ export interface Nota {
calificacion: number; // Nota numerica. 0 .. 10, el 0 representa el ausente.
}
export interface Notas {
courseId: string;
name: string;
notas: Nota[];
}
10 changes: 3 additions & 7 deletions lib/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as dotenv from 'dotenv';
import sigaScraper from '..';

dotenv.config();

const { SIGA_USER, SIGA_PASS } = process.env;

describe('Scrape Cursada', () => {
test('Deberia devolver un array de con informacion acerca asignaturas.', async (done) => {
try {
Expand All @@ -18,7 +13,6 @@ describe('Scrape Cursada', () => {
aula: '115',
sede: 'Campus',
color: '#7A94CF',
notas: [],
turno: 'Mañana',
dia: 3,
hora: '8:30',
Expand All @@ -31,7 +25,6 @@ describe('Scrape Cursada', () => {
aula: '102',
sede: 'Campus',
color: '#AF9772',
notas: [],
turno: 'Mañana',
dia: 3,
hora: '8:30',
Expand Down Expand Up @@ -61,6 +54,7 @@ describe('Scrape Notas', () => {

const expected = [
{
courseId: '950703',
name: 'Análisis Matemático II',
notas: [
{
Expand All @@ -74,6 +68,7 @@ describe('Scrape Notas', () => {
],
},
{
courseId: '950606',
name: 'Física II',
notas: [
{
Expand All @@ -92,6 +87,7 @@ describe('Scrape Notas', () => {
},
];
const scrapeResponse = await sigaScraper.scrapeNotas();

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

expect(scrapeResponse instanceof Array).toBeTruthy();
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siga-scraper",
"version": "1.1.2",
"version": "1.2.0",
"description": "Tool to scrape information from SIGA FRBA UTN.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -9,7 +9,7 @@
],
"scripts": {
"build": "tsc",
"test": "cross-env NODE_ENV=test jest --detectOpenHandles --forceExit --verbose"
"test": "tsc & cross-env NODE_ENV=test jest --detectOpenHandles --forceExit --verbose"
},
"repository": {
"type": "git",
Expand All @@ -36,7 +36,7 @@
"homepage": "https://github.com/NicoMigueles/siga-scraper#readme",
"jest": {
"preset": "ts-jest",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(ts|tsx)?$"
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(js)?$"
},
"devDependencies": {
"@types/dotenv": "^8.2.0",
Expand Down

0 comments on commit c59dca1

Please sign in to comment.