Skip to content

Commit

Permalink
added subjects codes to /schedule endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
digas99 committed Sep 25, 2022
1 parent d4017f8 commit a956c12
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 68 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ If everything is correct, this should be the response:
{
"subject": {
"name": "SEGURANÇA INFORMÁTICA E NAS ORGANIZAÇÕES",
"abbrev": "SIO"
"abbrev": "SIO",
"code": "42573"
},
"start": "9h",
"duration": "2h",
Expand All @@ -91,7 +92,8 @@ If everything is correct, this should be the response:
{
"subject": {
"name": "ARQUITETURA DE COMPUTADORES I",
"abbrev": "AC-I"
"abbrev": "AC-I",
"code": "41948"
},
"start": "14h",
"duration": "1h",
Expand All @@ -105,7 +107,8 @@ If everything is correct, this should be the response:
{
"subject": {
"name": "ARQUITETURA DE COMPUTADORES I",
"abbrev": "AC-I"
"abbrev": "AC-I",
"code": "41948"
},
"start": "9h",
"duration": "2h",
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [Changelog v1.0.5](https://github.com/digas99/paco-ua-api/releases/tag/v1.0.5)
Released on 25/09/2022

## Content
- Added subjects codes to /schedule endpoint

# [Changelog v1.0.4](https://github.com/digas99/paco-ua-api/releases/tag/v1.0.4)
Released on 23/09/2022

Expand Down
71 changes: 8 additions & 63 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ This API uses a headless browser to fetch data directly from [paco.ua.pt](https:
1. [Include Teachers](#include-teachers)
1. [Subject Program](#subject-program)
1. [Horário](#horário)   ```GET /schedule```
1. [Subject Schedule](#subject-schedule)
1. [Requerimentos](#requerimentos)   ```GET /requests```

---
Expand Down Expand Up @@ -868,6 +867,8 @@ RESPONSE: 4.5s 🟢
RESPONSE: 5s 🟡

```GET /schedule```

```GET /schedule/subject/<subject_code>```
```json5
// RESPONSE example
{
Expand All @@ -877,7 +878,8 @@ RESPONSE: 5s 🟡
{
"subject": {
"name": "SEGURANÇA INFORMÁTICA E NAS ORGANIZAÇÕES",
"abbrev": "SIO"
"abbrev": "SIO",
"code": "42573"
},
"start": "9h",
"duration": "2h",
Expand All @@ -888,7 +890,8 @@ RESPONSE: 5s 🟡
{
"subject": {
"name": "ARQUITETURA DE COMPUTADORES I",
"abbrev": "AC-I"
"abbrev": "AC-I",
"code": "41948"
},
"start": "14h",
"duration": "1h",
Expand All @@ -902,7 +905,8 @@ RESPONSE: 5s 🟡
{
"subject": {
"name": "ARQUITETURA DE COMPUTADORES I",
"abbrev": "AC-I"
"abbrev": "AC-I",
"code": "41948"
},
"start": "9h",
"duration": "2h",
Expand All @@ -923,65 +927,6 @@ RESPONSE: 5s 🟡
}
```

## Subject Schedule

RESPONSE: 4.5s 🟢

```GET /schedule/subject/<subject_code>```
```json5
// GET /schedule/subject/41949

// RESPONSE example
{
"data": {
"schedule": {
"Segunda": [
{
"subject": {
"name": "REDES DE COMUNICAÇÕES II",
"abbrev": "T1"
},
"start": "12h",
"duration": "1,5h",
"capacity": 101,
"room": "ANF. IV"
},
{
"subject": {
"name": "REDES DE COMUNICAÇÕES II",
"abbrev": "P1"
},
"start": "14,5h",
"duration": "2h",
"capacity": 18,
"room": "04.2.16"
},
...
],
"Terça": [],
"Quarta": [
{
"subject": {
"name": "REDES DE COMUNICAÇÕES II",
"abbrev": "P5"
},
"start": "14h",
"duration": "2h",
"capacity": 19,
"room": "04.3.30"
}
],
...
},
"school_year": "2021/2022",
"semester": 2
},
"url": "https://paco.ua.pt/secvirtual/horarios/desenho_horario.asp?tipo=1&value=-210320212",
"title": "Horário de REDES DE COMUNICAÇÕES II",
"timestamp": "2022-08-18T16:40:10.748Z"
}
```

---

## Requerimentos
Expand Down
3 changes: 3 additions & 0 deletions docs/paco-ua-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ components:
abbrev:
type: string
description: Abbreviation of the name of the subject
code:
type: string
description: Code of the subject
start:
type: string
description: Hour of the beginning of the class
Expand Down
8 changes: 6 additions & 2 deletions scrapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ module.exports = {
if (table) {
// info
const scheduleInfoElem = table.querySelector("tr").children[0];
let scheduleType;
let scheduleType, subjectsList;

// subject schedule
if (scheduleInfoElem.childNodes.length == 1) {
Expand All @@ -224,6 +224,9 @@ module.exports = {
const scheduleInfo = scheduleInfoElem.childNodes[2].wholeText;
data["school_year"] = scheduleInfo.split(" - ")[1].split("AnoLectivo: ")[1];
data["semester"] = Number(scheduleInfo.split(" - ")[2].split("º")[0]);

// subjects list
subjectsList = Array.from(new Set(Array.from(table.nextElementSibling.querySelectorAll("tr > td:nth-of-type(2)")).map(info => info.innerText.split(" (")[0].trim())));
}

// subjects
Expand All @@ -248,7 +251,8 @@ module.exports = {
subject = {
"subject": {
"name": titleData[0],
"abbrev": elem.childNodes[0].wholeText.split(" ")[0].replace("\n", "")
"abbrev": elem.childNodes[0].wholeText.split(" ")[0].replace("\n", ""),
"code": subjectsList.filter(subject => subject.split(" - ")[1] === titleData[0])[0].split(" - ")[0]
},
"start": titleData[2].split("INÍCIO: ")[1],
"duration": titleData[3].split("DURAÇÃO: ")[1],
Expand Down

0 comments on commit a956c12

Please sign in to comment.