Skip to content

Commit aa0e91f

Browse files
committed
fix: made the devicename correct and also made the agenda debug script work with the new .env config
1 parent 8d7ed80 commit aa0e91f

File tree

3 files changed

+856
-7
lines changed

3 files changed

+856
-7
lines changed

examples/agenda.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
22
import readline from "readline";
3-
import fs from "fs";
3+
import fs, { cpSync } from "fs";
44
import { getTimetableForPeriods } from "../src/routes/Agenda";
5+
import { LoginWithToken } from "../src";
6+
import dotenv from "dotenv";
7+
dotenv.config();
58

69
const rl = readline.createInterface({
710
input: process.stdin,
@@ -14,20 +17,32 @@ const askQuestion = (query: string): Promise<string> => {
1417

1518
const main = async () => {
1619
try {
17-
const url = await askQuestion("Enter the base URL (e.g., https://example.smartschool.be): ");
18-
const token = await askQuestion("Enter your access token: ");
19-
const userId = await askQuestion("Enter the user ID: ");
20-
const deviceId = await askQuestion("Enter the device ID: ");
20+
const url = process.env.INSTANCE_URL || await askQuestion("Enter the instance URL (e.g., https://example.com): ");
21+
const refreshToken = process.env.REFRESH_TOKEN || await askQuestion("Enter your refresh token: ");
22+
const userId = process.env.USER_ID || await askQuestion("Enter your user ID: ");
2123

2224
const periodStart = new Date(); // Default to today
2325
const periodEnd = new Date(new Date().setDate(periodStart.getDate() + 7)); // Default to 7 days from today
24-
26+
const data = await LoginWithToken(url, refreshToken, "android", "SmartSchool.js debug script", "1234567890");
27+
const token = data.accessToken;
28+
const deviceId = data.SMSCMobileID;
2529
console.log("\nFetching timetable...");
2630
const timetable = await getTimetableForPeriods(url, userId, token, deviceId, periodStart, periodEnd);
2731
fs.writeFileSync("timetable.json", JSON.stringify(timetable, null, 2));
32+
const tomorrow = new Date();
33+
tomorrow.setDate(tomorrow.getDate() + 2);
34+
const tomorrowDateString = tomorrow.toISOString().split("T")[0];
35+
36+
const lessonsForTomorrow = timetable
37+
.filter(day => new Date(day.date).toISOString().split("T")[0] === tomorrowDateString)
38+
.flatMap(day => day.lessons || []);
39+
2840

2941
console.log("\nTimetable fetched successfully:");
3042
console.log(JSON.stringify(timetable, null, 2));
43+
console.log("you have " + lessonsForTomorrow.length + " entries in your timetable for the next day");
44+
console.log("Details:", JSON.stringify(lessonsForTomorrow, null, 2));
45+
3146
} catch (error) {
3247
console.error("\nAn error occurred:");
3348
console.error(error);

src/routes/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const RegisterDevice = async (
2929
const body = {
3030
accessToken,
3131
deviceType,
32-
deviceName,
32+
"deviceTitle": deviceName,
3333
deviceId
3434
};
3535

0 commit comments

Comments
 (0)