assignment-upload-file.ts
1 import * as pronote from "../src"; 2 import { credentials } from "./_credentials"; 3 4 void async function main () { 5 const handle = pronote.createSessionHandle(); 6 await pronote.loginCredentials(handle, { 7 url: credentials.pronoteURL, 8 kind: pronote.AccountKind.STUDENT, 9 username: credentials.username, 10 password: credentials.password, 11 deviceUUID: credentials.deviceUUID 12 }); 13 14 // Grab all the assignments for week 1 through week 4. 15 const assignments = await pronote.assignmentsFromWeek(handle, 1, 4); 16 17 console.log("---"); 18 19 for (const assignment of assignments) { 20 console.log(assignment.subject.name, "to finish before the", assignment.deadline.toLocaleString()); 21 console.log("(description) =>", assignment.description); 22 23 if (assignment.return.canUpload) { 24 const fileName = "hello-world.txt"; 25 26 const encoder = new TextEncoder(); 27 const buffer = encoder.encode(`Hello, world! This file was sent by Pawnote, the ${Date.now()} !`); 28 const file = new Blob([buffer], { type: "text/plain" }); 29 30 await pronote.assignmentUploadFile(handle, assignment.id, file, fileName); 31 console.info("(upload) => successfully uploaded", fileName); 32 } 33 34 console.log("---"); 35 } 36 }();