Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting on /gradebook page #21

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 42 additions & 92 deletions src/app/api/get_assignments_current/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { NextRequest, NextResponse } from "next/server";
import { cookies } from "next/headers";
import cheerio from "cheerio";
import { Assignment } from "@/types";
import { parse } from "path";
import zlib from "zlib";
import { getCurrentQuarterOid } from "@/utils/getCurrentQuarter";
import { processAssignments } from "@/utils/processData";

export async function GET(req: NextRequest, res: NextResponse) {
try {
Expand All @@ -22,42 +21,42 @@ export async function GET(req: NextRequest, res: NextResponse) {
Cookie: `JSESSIONID=${sessionId}`
},
}).then(res => res.text()).then(html => {
const $ = cheerio.load(html);

const assignments: Assignment[] = [];

const tableRows = $("#dataGrid > table > tbody > tr.listCell");

tableRows.each((index, row) => {
const assignmentName = $(row).children("td:nth-child(3)").text();
const dueDate = $(row).children("td:nth-child(5)").text();
const category = $(row).children("td:nth-child(2)").text();
const points = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[1];
const earned = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[0];
const feedback = $(row).children("td:nth-child(7)").text();

if (assignmentName) {

const assignment = {
name: assignmentName,
dueDate: dueDate ? dueDate : null,
gradeCategory: category ? category : null,
points: points ? parseFloat(points) : null,
earned: earned ? parseFloat(earned) : null,
feedback: feedback ? feedback : null
};

assignments.push(assignment);
}
const { assignments, more } = processAssignments(html);

if (more) {
fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
headers: {
Cookie: `JSESSIONID=${sessionId}`
},
method: "POST",
body: new URLSearchParams({
"org.apache.struts.taglib.html.TOKEN": apacheToken ? apacheToken : "",
"userEvent": "10",
"gradeTermOid": getCurrentQuarterOid(),
}),
}).then(async res => {
const html = await res.text();

assignments.push(...processAssignments(html).assignments);
});

})
fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
headers: {
Cookie: `JSESSIONID=${sessionId}`
},
method: "POST",
body: new URLSearchParams({
"org.apache.struts.taglib.html.TOKEN": apacheToken ? apacheToken : "",
"userEvent": "20",
"gradeTermOid": getCurrentQuarterOid(),
}),
});
}

assingmentsList.push(assignments);
});

for (let i = 0; i < classes - 1; i++) {
const assignments: Assignment[] = [];

await fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
headers: {
Cookie: `JSESSIONID=${sessionId}`
Expand All @@ -69,38 +68,10 @@ export async function GET(req: NextRequest, res: NextResponse) {
"gradeTermOid": getCurrentQuarterOid(),
}),
}).then(res => res.text()).then(async html => {
const $ = cheerio.load(html);

const tableRows = $("#dataGrid > table > tbody > tr.listCell");

tableRows.each((index, row) => {
const assignmentName = $(row).children("td:nth-child(3)").text();
const dueDate = $(row).children("td:nth-child(5)").text();
const category = $(row).children("td:nth-child(2)").text();
const points = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[1];
const earned = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[0];
const feedback = $(row).children("td:nth-child(7)").text();
const { assignments, more } = processAssignments(html);

if (assignmentName) {

const assignment = {
name: assignmentName,
dueDate: dueDate ? dueDate : null,
gradeCategory: category ? category : null,
points: points ? parseFloat(points) : null,
earned: earned ? parseFloat(earned) : null,
feedback: feedback ? feedback : null
};

assignments.push(assignment);
}

});

const recordsCount = parseInt($("#totalRecordsCount")?.text() || "0");

if (recordsCount > 25) {
await fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
if (more) {
fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
headers: {
Cookie: `JSESSIONID=${sessionId}`
},
Expand All @@ -112,48 +83,25 @@ export async function GET(req: NextRequest, res: NextResponse) {
}),
}).then(async res => {
const html = await res.text();
const $ = cheerio.load(html);

const tableRows = $("#dataGrid > table > tbody > tr.listCell");

tableRows.each((index, row) => {
const assignmentName = $(row).children("td:nth-child(3)").text();
const dueDate = $(row).children("td:nth-child(5)").text();
const category = $(row).children("td:nth-child(2)").text();
const points = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[1];
const earned = $(row).find("td:nth-child(6) > table > tbody > tr > td:nth-child(2)").text().split("/")[0];
const feedback = $(row).children("td:nth-child(7)").text();

if (assignmentName) {

const assignment = {
name: assignmentName,
dueDate: dueDate ? dueDate : null,
gradeCategory: category ? category : null,
points: points ? parseFloat(points) : null,
earned: earned ? parseFloat(earned) : null,
feedback: feedback ? feedback : null
};

assignments.push(assignment);
}

});
assignments.push(...processAssignments(html).assignments);
});

fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
headers: {
Cookie: `JSESSIONID=${sessionId}`
}, method: "POST",
},
method: "POST",
body: new URLSearchParams({
"org.apache.struts.taglib.html.TOKEN": apacheToken ? apacheToken : "",
"userEvent": "20",
"gradeTermOid": getCurrentQuarterOid(),
}),
});
}
});

assingmentsList.push(assignments);
assingmentsList.push(assignments);
});
}

await fetch("https://aspen.cpsd.us/aspen/portalAssignmentList.do?navkey=academics.classes.list.gcd", {
Expand All @@ -168,6 +116,8 @@ export async function GET(req: NextRequest, res: NextResponse) {
}),
})

console.log(assingmentsList);

const elapsedTime = new Date().getTime() - startTime.getTime();
console.log("\x1b[32m ✓\x1b[0m scraped assignments in", elapsedTime, "ms");
return new Response(JSON.stringify(assingmentsList), { status: 200 });
Expand Down
47 changes: 28 additions & 19 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
--background-color: #000000;
--text-color: #ffffff;
--alt-background-color: #1f1f1f;
--inside-padding: 15px;
--alt-text-color: #c0c0c0;
--inside-padding: 20px;
--link-hightlight: rgb(68, 255, 49);
--link-hightlightTrans: #8d7cff40;
--uniMargin: 20px;
Expand All @@ -20,7 +21,7 @@ body {
align-items: center;
padding: var(--inside-padding);
background-color: var(--alt-background-color);
border-radius: 20px;
border-radius: 10px;
}

.navlinks a {
Expand Down Expand Up @@ -113,19 +114,22 @@ body {

.grades-table {
width: 100%;
padding-bottom: 20px;
margin-bottom: 20px;
border-bottom: #ffffff 1px solid;
}

.grades-table tr td:nth-child(3) {
.grades-table tr td:nth-child(2) {
text-align: right;
font-weight: 700;
}

.grades-table tr td:nth-child(5) {
.grades-table tr td:nth-child(4) {
text-align: right;
width: 0%;
}

.grades-table tr td:nth-child(4) {
.grades-table tr td:nth-child(3) {
text-align: center;
width: 0%;
padding: 0 20px;
Expand All @@ -136,29 +140,18 @@ body {
padding: 10px 0;
}

.grades-table tr th:nth-child(3) {
.grades-table tr th:nth-child(2) {
text-align: right;
}

.grades-table tr th:nth-child(4) {
.grades-table tr th:nth-child(3) {
text-align: center;
}

.grades-table tr th:nth-child(5) {
.grades-table tr th:nth-child(4) {
text-align: right;
}

.dropdown-icon {
cursor: pointer;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
width: 0%;
padding-right: 8px;
}

.gpa-container {
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -314,4 +307,20 @@ a {

.checkbox-container label {
margin-top: 100px;
}

.placeholder-text {
text-align: center;
font-style: italic;
width: 100%;
margin-top: 20px;
color: var(--alt-text-color);
}

.assignments-table {
width: 100%;
}

.class-row {
cursor: not-allowed;
}
Loading