Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const skyward = require('skyward-rest');
- // Define the URL of the Skyward login page for your district
- const loginURL = 'https://skyward1.bhisd.net/scripts/wsisa.dll/WService=wsEAplus/skyportlogin.w';
- // Create a scraper object
- const scraper = skyward(loginURL);
- // Define the username and password for the student
- const username = 'your_username';
- const password = 'your_password';
- // Function to find all 7 courses the user is taking
- async function findAllCoursesAndGrades(username, password) {
- try {
- // Scrape the gradebook for all courses
- const gradebook = await scraper.scrapeGradebook(username, password);
- // Extract course names and their corresponding grades
- const coursesAndGrades = {};
- gradebook.data.forEach(course => {
- const courseName = course.courseName;
- const grade = course.gradebook[0].score; // Assuming the first gradebook entry is the overall grade
- coursesAndGrades[courseName] = grade;
- });
- return coursesAndGrades;
- } catch (error) {
- throw new Error('Error scraping gradebook: ' + error.message);
- }
- }
- // Function to calculate the average grade
- function calculateAverageGrade(coursesAndGrades) {
- const grades = Object.values(coursesAndGrades);
- const sum = grades.reduce((acc, grade) => acc + grade, 0);
- const average = sum / grades.length;
- return average.toFixed(2); // Round to 2 decimal places
- }
- // Call the function to find all courses and grades
- findAllCoursesAndGrades(username, password)
- .then(coursesAndGrades => {
- // Output all courses and their corresponding grades
- console.log("All 7 Courses and Their Grades:");
- Object.entries(coursesAndGrades).forEach(([courseName, grade]) => {
- console.log(`${courseName} - ${grade}`);
- });
- // Calculate and output the average grade
- const averageGrade = calculateAverageGrade(coursesAndGrades);
- console.log(`\nAverage Grade: ${averageGrade}`);
- })
- .catch(error => {
- console.error(error);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement