Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Pequenas atualizações - UNILAB
Browse files Browse the repository at this point in the history
  • Loading branch information
Diassisfilho committed Nov 15, 2023
1 parent 38c2bff commit b2ccc02
Show file tree
Hide file tree
Showing 47 changed files with 616 additions and 176 deletions.
3 changes: 2 additions & 1 deletion examples/download-all-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fs = require('fs');
const path = require('path');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});
// Pasta para salvar os arquivos
const BaseDestiny = path.resolve('.', 'downloads');
Expand Down
3 changes: 2 additions & 1 deletion examples/get-absences.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-account-info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-activities.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-courses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-grades-simultaneously.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-grades.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-homework.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-lessons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
3 changes: 2 additions & 1 deletion examples/get-news.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// coloque seu usuário
Expand Down
30 changes: 30 additions & 0 deletions examples/login-with-session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { Sigaa, SigaaCookiesController } = require('sigaa-api');

const sigaaURL = new URL('https://sigaa.ifsc.edu.br');
const institution = 'IFSC';

const cookie = "" // coloque seu cookie JSESSIONID
const JSESSIONID = `JSESSIONID=${cookie}`;

const main = async () => {
const cookiesController = new SigaaCookiesController();
cookiesController.storeCookies(sigaaURL.hostname, [JSESSIONID]);

const sigaa = new Sigaa({
url: sigaaURL.href,
institution,
cookiesController
});

const http = sigaa.httpFactory.createHttp();
const page = await http.get("/sigaa/vinculos.jsf");
const account = await sigaa.accountFactory.getAccount(page);

console.log('> Nome: ' + (await account.getName()));
console.log('> Emails: ' + (await account.getEmails()).join(', '));
console.log('> Url foto: ' + (await account.getProfilePictureURL()));
}

main().catch((err) => {
if (err) console.log(err);
});
3 changes: 2 additions & 1 deletion examples/search-teacher.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

const searchTerm = 'José'; // Nome do professor para procurar
Expand Down
3 changes: 2 additions & 1 deletion examples/use-another-institution.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Sigaa } = require('sigaa-api');

const sigaa = new Sigaa({
url: 'https://sigaa.ifsc.edu.br'
url: 'https://sigaa.ifsc.edu.br',
institution: 'IFSC'
});

// Ou
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sigaa-api",
"description": "Unofficial high performance API for SIGAA IFSC using web scraping.",
"version": "1.0.34",
"version": "1.0.35",
"main": "dist/sigaa-all-types.js",
"types": "dist/sigaa-all-types.d.ts",
"author": "Geovane Schmitz <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions src/account/sigaa-account-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SigaaAccountIFSC } from './sigaa-account-ifsc';
import { SigaaAccountUFPB } from './sigaa-account-ufpb';
import { SigaaAccountUNILAB } from './sigaa-account-unilab';
import { SigaaAccountUNB } from './sigaa-account-unb';
import { SigaaAccountInstitutionMap } from '@session/sigaa-institution-controller';

/**
* Abstraction to represent the class that instantiates the account.
Expand Down Expand Up @@ -38,14 +39,13 @@ export class SigaaAccountFactory implements AccountFactory {
* @param page home page of account (page after login).
*/
async getAccount(page: Page): Promise<Account> {
const SigaaAccountInstitution = {
const SigaaAccountInstitution: SigaaAccountInstitutionMap = {
IFSC: SigaaAccountIFSC,
UFPB: SigaaAccountUFPB,
UNB: SigaaAccountUNB,
UNILAB: SigaaAccountUNILAB
};
const institution = this.session.institution;
return new SigaaAccountInstitution[institution](
return new SigaaAccountInstitution[this.session.institution](
page,
this.http,
this.parser,
Expand Down
2 changes: 1 addition & 1 deletion src/account/sigaa-account-ifsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Parser } from '@helpers/sigaa-parser';
import { HTTP, ProgressCallback } from '@session/sigaa-http';
import { Session } from '@session/sigaa-session';
import { LoginStatus } from '../sigaa-types';
import { URL } from 'url';
import { BondFactory, BondType } from '@bonds/sigaa-bond-factory';
import { Page } from '@session/sigaa-page';
import { Account } from './sigaa-account';
import { URL } from 'url';

/**
* Responsible for representing the user account.
Expand Down
2 changes: 1 addition & 1 deletion src/account/sigaa-account-ufpb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Parser } from '@helpers/sigaa-parser';
import { HTTP, ProgressCallback } from '@session/sigaa-http';
import { Session } from '@session/sigaa-session';
import { LoginStatus } from '../sigaa-types';
import { URL } from 'url';
import { BondFactory, BondType } from '@bonds/sigaa-bond-factory';
import { Page } from '@session/sigaa-page';
import { Account } from './sigaa-account';
import { URL } from 'url';

/**
* Responsible for representing the user account.
Expand Down
6 changes: 5 additions & 1 deletion src/account/sigaa-account-unb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Parser } from '@helpers/sigaa-parser';
import { HTTP, ProgressCallback } from '@session/sigaa-http';
import { Session } from '@session/sigaa-session';
import { LoginStatus } from '../sigaa-types';
import { URL } from 'url';
import { BondFactory, BondType } from '@bonds/sigaa-bond-factory';
import { Page } from '@session/sigaa-page';
import { Account } from './sigaa-account';
import { URL } from 'url';

/**
* Responsible for representing the user account.
Expand Down Expand Up @@ -94,6 +94,10 @@ export class SigaaAccountUNB implements Account {
this.pagehomeParsePromise = this.http
.get(homepage.url.href, { noCache: true })
.then((page) => this.parseBondPage(page));
} else if (homepage.url.href.includes('/sigaa/telaAvisoLogon.jsf')) {
this.pagehomeParsePromise = this.http
.get('/sigaa/vinculos.jsf')
.then((page) => this.parseBondPage(page));
} else {
throw new Error('SIGAA: Unknown homepage format.');
}
Expand Down
12 changes: 12 additions & 0 deletions src/account/sigaa-account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ProgressCallback } from '@session/sigaa-http';
import { URL } from 'url';
import { BondType } from '@bonds/sigaa-bond-factory';
import { SigaaAccountIFSC } from './sigaa-account-ifsc';
import { SigaaAccountUFPB } from './sigaa-account-ufpb';
import { SigaaAccountUNB } from './sigaa-account-unb';
import { SigaaAccountUNILAB } from './sigaa-account-unilab';

/**
* Abstraction of account type.
Expand Down Expand Up @@ -66,3 +70,11 @@ export interface Account {
*/
changePassword(oldPassword: string, newPassword: string): Promise<void>;
}

export type SigaaAccountInstitution =
| SigaaAccountIFSC
| SigaaAccountUFPB
| SigaaAccountUNB
| SigaaAccountUNILAB;

export type CommonSigaaAccount = Account & SigaaAccountInstitution;
2 changes: 1 addition & 1 deletion src/bonds/sigaa-bond-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CourseFactory } from '@courses/sigaa-course-student-factory';
import { Parser } from '@helpers/sigaa-parser';
import { HTTP } from '@session/sigaa-http';
import { HTTPFactory } from '@session/sigaa-http-factory';

import { URL } from 'url';
import { SigaaStudentBond, StudentBond } from './sigaa-student-bond';
import { SigaaTeacherBond, TeacherBond } from './sigaa-teacher-bond';

Expand Down
2 changes: 1 addition & 1 deletion src/bonds/sigaa-student-bond.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CourseFactory } from '@courses/sigaa-course-student-factory';
import { Parser } from '@helpers/sigaa-parser';
import { HTTP } from '@session/sigaa-http';

import { URL } from 'url';
import {
CourseStudent,
CourseStudentData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export interface WebContent extends UpdatableResource<WebContentData> {
*/
export class SigaaWebContent
extends AbstractUpdatableResource
implements WebContent {
implements WebContent
{
readonly type = 'webcontent';

private _title!: string;
Expand Down
1 change: 0 additions & 1 deletion src/courses/resources/forum/sigaa-course-forum-student.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { URL } from 'url';

import { FormData } from 'formdata-node';
import { Parser } from '@helpers/sigaa-parser';
import { File, FileData } from '@resources/sigaa-file';
Expand Down
4 changes: 1 addition & 3 deletions src/courses/sigaa-course-student.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { URL } from 'url';

import { Lesson } from '@courseResources/sigaa-lesson-student';
import { NewsData, News } from '@courseResources/sigaa-news-student';
import { Parser } from '@helpers/sigaa-parser';
import { File } from '@resources/sigaa-file';
import { HTTP } from '@session/sigaa-http';

import { URL } from 'url';
import { SigaaForm, Page } from '@session/sigaa-page';
import { QuizData, Quiz } from '@attachments/sigaa-quiz-student';
import { HomeworkData, Homework } from '@attachments/sigaa-homework-student';
Expand Down
1 change: 0 additions & 1 deletion src/search/sigaa-search-teacher-result.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Parser } from '@helpers/sigaa-parser';
import { HTTP, ProgressCallback } from '@session/sigaa-http';
import { URL } from 'url';

/**
* @category Internal
Expand Down
1 change: 0 additions & 1 deletion src/search/sigaa-search-teacher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Parser } from '@helpers/sigaa-parser';
import { HTTP } from '@session/sigaa-http';
import { Page } from '@session/sigaa-page';
import { URL } from 'url';
import {
TeacherResult,
SigaaSearchTeacherResult
Expand Down
15 changes: 10 additions & 5 deletions src/session/login/sigaa-login-ifsc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { LoginStatus } from '../../sigaa-types';
import { URL } from 'url';
import { HTTP } from '../sigaa-http';
import { Page, SigaaForm } from '../sigaa-page';
import { Session } from '../sigaa-session';
import { Login } from './sigaa-login';
import { IFSCPage } from '@session/page/sigaa-page-ifsc';
import { SigaaForm } from '@session/sigaa-page';

/**
* Responsible for logging in IFSC.
Expand All @@ -13,7 +14,7 @@ export class SigaaLoginIFSC implements Login {
constructor(protected http: HTTP, protected session: Session) {}
readonly errorInvalidCredentials = 'SIGAA: Invalid credentials.';

protected parseLoginForm(page: Page): SigaaForm {
protected parseLoginForm(page: IFSCPage): SigaaForm {
const formElement = page.$("form[name='loginForm']");

const actionUrl = formElement.attr('action');
Expand Down Expand Up @@ -56,7 +57,7 @@ export class SigaaLoginIFSC implements Login {
protected async desktopLogin(
username: string,
password: string
): Promise<Page> {
): Promise<IFSCPage> {
const { action, postValues } = await this.getLoginForm();

postValues['user.login'] = username;
Expand All @@ -70,7 +71,11 @@ export class SigaaLoginIFSC implements Login {
* @param username
* @param password
*/
async login(username: string, password: string, retry = true): Promise<Page> {
async login(
username: string,
password: string,
retry = true
): Promise<IFSCPage> {
if (this.session.loginStatus === LoginStatus.Authenticated)
throw new Error('SIGAA: This session already has a user logged in.');
try {
Expand All @@ -85,7 +90,7 @@ export class SigaaLoginIFSC implements Login {
}
}

protected async parseDesktopLoginResult(page: Page): Promise<Page> {
protected async parseDesktopLoginResult(page: IFSCPage): Promise<IFSCPage> {
const accountPage = await this.http.followAllRedirect(page);
if (accountPage.bodyDecoded.includes('Entrar no Sistema')) {
if (accountPage.bodyDecoded.includes('Usuário e/ou senha inválidos')) {
Expand Down
Loading

0 comments on commit b2ccc02

Please sign in to comment.