Advertisement
apad464

SkywardGradeAverage.js

Feb 9th, 2024
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.10 KB | Source Code | 0 0
  1. const skyward = require('skyward-rest');
  2.  
  3. // Define the URL of the Skyward login page for your district
  4. const loginURL = 'https://skyward1.bhisd.net/scripts/wsisa.dll/WService=wsEAplus/skyportlogin.w';
  5.  
  6. // Create a scraper object
  7. const scraper = skyward(loginURL);
  8.  
  9. // Define the username and password for the student
  10. const username = 'your_username';
  11. const password = 'your_password';
  12.  
  13. // Function to find all 7 courses the user is taking
  14. async function findAllCoursesAndGrades(username, password) {
  15.     try {
  16.         // Scrape the gradebook for all courses
  17.         const gradebook = await scraper.scrapeGradebook(username, password);
  18.        
  19.         // Extract course names and their corresponding grades
  20.         const coursesAndGrades = {};
  21.         gradebook.data.forEach(course => {
  22.             const courseName = course.courseName;
  23.             const grade = course.gradebook[0].score; // Assuming the first gradebook entry is the overall grade
  24.             coursesAndGrades[courseName] = grade;
  25.         });
  26.        
  27.         return coursesAndGrades;
  28.     } catch (error) {
  29.         throw new Error('Error scraping gradebook: ' + error.message);
  30.     }
  31. }
  32.  
  33. // Function to calculate the average grade
  34. function calculateAverageGrade(coursesAndGrades) {
  35.     const grades = Object.values(coursesAndGrades);
  36.     const sum = grades.reduce((acc, grade) => acc + grade, 0);
  37.     const average = sum / grades.length;
  38.     return average.toFixed(2); // Round to 2 decimal places
  39. }
  40.  
  41. // Call the function to find all courses and grades
  42. findAllCoursesAndGrades(username, password)
  43.     .then(coursesAndGrades => {
  44.         // Output all courses and their corresponding grades
  45.         console.log("All 7 Courses and Their Grades:");
  46.         Object.entries(coursesAndGrades).forEach(([courseName, grade]) => {
  47.             console.log(`${courseName} - ${grade}`);
  48.         });
  49.  
  50.         // Calculate and output the average grade
  51.         const averageGrade = calculateAverageGrade(coursesAndGrades);
  52.         console.log(`\nAverage Grade: ${averageGrade}`);
  53.     })
  54.     .catch(error => {
  55.         console.error(error);
  56.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement