11process . env . NODE_TLS_REJECT_UNAUTHORIZED = "0"
22import readline from "readline" ;
3- import fs from "fs" ;
3+ import fs , { cpSync } from "fs" ;
44import { getTimetableForPeriods } from "../src/routes/Agenda" ;
5+ import { LoginWithToken } from "../src" ;
6+ import dotenv from "dotenv" ;
7+ dotenv . config ( ) ;
58
69const rl = readline . createInterface ( {
710 input : process . stdin ,
@@ -14,20 +17,32 @@ const askQuestion = (query: string): Promise<string> => {
1417
1518const 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 ) ;
0 commit comments