示例#1
0
        public Student GetAllStudentInfo(string link)
        {
            //loads and fetches data
            var studentData     = RequestData.GetData(_httpClient, link, ResponseType.Registration);
            var registrationDoc = new HtmlDocument();

            registrationDoc.LoadHtml(studentData.Result);

            var studentName = Utils.FormatName(registrationDoc.GetElementbyId("plnMain_lblRegStudentName").InnerText,
                                               false);
            var birthDate     = registrationDoc.GetElementbyId("plnMain_lblBirthDate").InnerText;
            var counselorName =
                Utils.FormatName(registrationDoc.GetElementbyId("plnMain_lblCounselor").InnerText, false);
            var counselorEmail = registrationDoc.GetElementbyId("plnMain_lblCounselor").FirstChild.Attributes[0].Value
                                 .Substring(7);
            var buildingName = registrationDoc.GetElementbyId("plnMain_lblBuildingName").InnerText;
            var gender       = registrationDoc.GetElementbyId("plnMain_lblGender").InnerText;
            var calender     = registrationDoc.GetElementbyId("plnMain_lblCalendar").InnerText;
            var grade        = registrationDoc.GetElementbyId("plnMain_lblGrade").InnerText;
            var language     = registrationDoc.GetElementbyId("plnMain_lblLanguage").InnerText;

            return(new Student {
                StudentName = studentName,
                BirthDate = birthDate,
                CounselorName = counselorName,
                CounselorEmail = counselorEmail,
                Building = buildingName,
                Gender = gender,
                Calendar = calender,
                Grade = grade,
                Language = language
            });
        }
示例#2
0
        public List <List <List <Day> > > GetAttendances(string link)
        {
            var calendarList = new List <List <List <Day> > >();
            var documentList = new List <HtmlDocument>();
            var data         = RequestData.GetData(_httpClient, link, ResponseType.MonthlyView, "Attendance");

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(data.Result);

            var form      = new AttendanceForm(htmlDocument);
            var monthKeys = form.MonthKeys();

            foreach (var key in monthKeys)
            {
                var body     = form.GenerateFormBody(key);
                var response = RequestData.GetDataWithBody(_httpClient, link, ResponseType.MonthlyView, body,
                                                           "Attendance");
                var doc = new HtmlDocument();
                doc.LoadHtml(response.Result);
                documentList.Add(doc);
            }

            foreach (var document in documentList)
            {
                var calendar        = new List <List <Day> >();
                var attendanceTable = document.GetElementbyId("plnMain_cldAttendance");
                var weeks           = attendanceTable.ChildNodes.ToList();
                weeks.RemoveRange(0, 3);
                weeks.RemoveRange(weeks.Count - 2, 2);
                foreach (var week in weeks)
                {
                    var calendarWeek = new List <Day>();
                    foreach (var(item, index) in week.ChildNodes.WithIndex())
                    {
                        if (!int.TryParse(item.InnerText, out var date))
                        {
                            break;
                        }

                        var attendances = new List <AttendanceRecord>();
                        var dayAttrs    = item.Attributes;
                        if (dayAttrs.Contains("title"))
                        {
                            var records = dayAttrs["title"].Value;
                            foreach (var line in new LineReader(() => new StringReader(records)))
                            {
                                if (attendances[^ 1].Reason == null)
        public List <List <Course> > CheckReportCardTask(string link)
        {
            //fetches and loads data
            var reportCardData     = RequestData.GetData(_httpClient, link, ResponseType.ReportCards);
            var reportCardDocument = new HtmlDocument();

            reportCardDocument.LoadHtml(reportCardData.Result);
            //checks the reporting period
            var reportCardHeader = reportCardDocument.DocumentNode.Descendants("div")
                                   .FirstOrDefault(node => node.GetAttributeValue("class", "")
                                                   .Equals("sg-header"));
            //gets reporting period number
            var reportCardNumber = reportCardHeader.Descendants("label")
                                   .FirstOrDefault(node => node.GetAttributeValue("id", "")
                                                   .Equals("plnMain_lblTitle")).InnerText.Trim();

            var reportingPeriod = byte.Parse(reportCardNumber.ElementAt(33).ToString());

            return(Enumerable.Range(1, reportingPeriod).Select(period => GetReportCard(reportCardDocument, period))
                   .ToList());
        }
        public List <List <TranscriptCourse> > GetTranscript(string link)
        {
            var data         = RequestData.GetData(_httpClient, link, ResponseType.Transcript).Result;
            var courseList   = new List <List <TranscriptCourse> >();
            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(data); //gets all of the years
            var transcriptGroups = htmlDocument.DocumentNode.SelectNodes("//td[@class='sg-transcript-group']");

            foreach (var group in transcriptGroups)
            {
                var yearlyCourses = new List <TranscriptCourse>();
                var oldCourseHtml = group.Descendants("table")
                                    .Where(node => node.GetAttributeValue("class", "")
                                           .Equals("sg-asp-table")).ToList();
                var oldCourseItemList = oldCourseHtml[0].Descendants("tr")
                                        .Where(node => node.GetAttributeValue("class", "")
                                               .Equals("sg-asp-table-data-row")).ToList();
                foreach (var courseHtmlItem in oldCourseItemList)     //foreach course that is listed in a year
                {
                    var courseName = courseHtmlItem.Descendants("td") //gets course name
                                     .ElementAt(1).InnerText
                                     .Trim();                         //course name is stored at the second instance of td

                    var courseId = courseHtmlItem.Descendants("td")   //gets course id
                                   .ElementAt(0).InnerText
                                   .Trim();                           //course name is stored at the first instance of td

                    courseId = courseId.Remove(courseId.Length - 4);

                    courseName = Utils.BeautifyCourseInfo(courseName).Item1;

                    while (courseId.LastOrDefault() == ' ' || courseId.LastOrDefault() == '-' ||
                           courseId.LastOrDefault() == 'A' || courseId.LastOrDefault() == 'B' ||
                           courseId.LastOrDefault() == 'Y' || courseId.LastOrDefault() == 'M')
                    {
                        courseId = courseId.TrimEnd(courseId[^ 1]);
示例#5
0
        public List <List <Course> > GetGradesFromIpr(string link)
        {
            var iprList      = new List <List <Course> >();
            var documentList = new List <HtmlDocument>();
            var data         = RequestData.GetData(_httpClient, link, ResponseType.InterimProgress);

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(data.Result);

            var form         = new IprForm(htmlDocument);
            var iprDateNames = form.IprDateNames();

            foreach (var name in iprDateNames)
            {
                var body     = form.GenerateFormBody(name);
                var response = RequestData.GetDataWithBody(_httpClient, link, ResponseType.InterimProgress, body);
                var doc      = new HtmlDocument();
                doc.LoadHtml(response.Result);
                documentList.Add(doc);
            }

            foreach (var document in documentList)
            {
                var courseList = new List <Course>();
                var iprTable   = document.GetElementbyId("plnMain_dgIPR");
                var iprCourses = iprTable.ChildNodes.Where(node => node.GetAttributeValue("class", "")
                                                           .Equals("sg-asp-table-data-row")).ToList();
                foreach (var iprCourse in iprCourses)               //foreach course
                {
                    var courseNameNode = iprCourse.Descendants("a") //gets course name
                                         .FirstOrDefault(node => node.GetAttributeValue("href", "")
                                                         .Equals("#"));

                    var courseIdNode = iprCourse.Descendants("td") //gets course id
                                       .FirstOrDefault();

                    string courseName;
                    var    courseId = courseName = Empty;

                    if (courseNameNode != null && courseIdNode != null)
                    {
                        courseName = courseNameNode.InnerText.Trim();
                        courseId   = courseIdNode.InnerText.Trim();
                    }

                    var grade = iprCourse.Descendants("td") //gets course grade
                                .ElementAt(5).InnerText.Trim();

                    var courseInfo = Utils.BeautifyCourseInfo(courseName, courseId);
                    (courseName, courseId) = courseInfo;

                    courseList.Add(new Course {
                        CourseId      = courseId,
                        CourseName    = courseName,
                        CourseAverage = double.Parse(grade)
                    }); //turns the grade (string) received into a double
                }

                iprList.Add(courseList);
            }

            return(iprList);
        }
        public List <List <AssignmentCourse> > GetAssignmentsFromMarkingPeriod(string link)
        {
            var courseList   = new List <List <AssignmentCourse> >();
            var documentList = new List <HtmlDocument>();
            var data         = RequestData.GetData(_httpClient, link, ResponseType.Assignments);

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(data.Result);

            var form = new GradesForm(htmlDocument);
            var reportingPeriodNames = form.ReportingPeriodNames();

            foreach (var name in reportingPeriodNames)
            {
                var body     = form.GenerateFormBody(name);
                var response = RequestData.GetDataWithBody(_httpClient, link, ResponseType.Assignments, body);
                var doc      = new HtmlDocument();
                doc.LoadHtml(response.Result);
                documentList.Add(doc);
            }

            foreach (var(htmlDocument1, run) in documentList.WithIndex())
            {
                var localCourseList = new List <AssignmentCourse>();
                var courseHtml      = htmlDocument1.DocumentNode.Descendants("div")
                                      .Where(node => node.GetAttributeValue("class", "")
                                             .Equals("AssignmentClass")).ToList();

                foreach (var(htmlNode, i) in courseHtml.WithIndex())
                {
                    var courseNode = htmlNode.Descendants("a")
                                     .FirstOrDefault(node => node.GetAttributeValue("class", "")
                                                     .Equals("sg-header-heading"));

                    if (courseNode == null)
                    {
                        continue;
                    }

                    //gets teacher information (name and room)
                    //gets section key
                    var sectionKey = courseNode.Attributes["onclick"].Value;

                    sectionKey = Regex.Match(sectionKey, @"\d+").Groups[0].Value;
                    var param = $"?section_key={sectionKey}&rcrun={run + 1}";

                    //gets html for popup
                    var popUpData = RequestData.GetData(_httpClient, link, ResponseType.ClassPopUp, "Student", param);
                    var popUpDoc  = new HtmlDocument();
                    popUpDoc.LoadHtml(popUpData.Result);

                    //extracts info
                    var sessionInfo = popUpDoc.GetElementbyId("plnMain_dgSessionInfo");
                    var sessionData = sessionInfo.ChildNodes[2].ChildNodes;
                    var teacherName = Utils.FormatName(sessionData[1].InnerText.Trim(), true);
                    var teacherRoom = sessionData[2].InnerText.Trim();

                    //gets and formats course info
                    var course = courseNode.InnerText.Trim();
                    var x      = new Regex(@"\w+\s-\s\d\s");

                    var courseName = x.Replace(course, @"").Trim();
                    var courseId   = x.Match(course).ToString().Trim();

                    var courseInfo = Utils.BeautifyCourseInfo(courseName, courseId);
                    (courseName, courseId) = courseInfo;

                    string courseGrade;
                    try {
                        courseGrade = htmlDocument1
                                      .GetElementbyId($"plnMain_rptAssigmnetsByCourse_lblOverallAverage_{i}")
                                      .InnerText.Trim();
                    }
                    catch {
                        continue;
                    }

                    //Gets grading information
                    //Prone to error as this typo is a hac problem
                    var courseInfoTable =
                        htmlDocument1.GetElementbyId($"plnMain_rptAssigmnetsByCourse_dgCourseCategories_{i}");
                    var gradeData = courseInfoTable.Descendants("tr").Where(node => node.GetAttributeValue("class", "")
                                                                            .Equals("sg-asp-table-data-row"));

                    string gradeType = null;
                    double totalPointsMax, totalPointsPercent, gradeScaleTotal, gradeScaleEarned;
                    var    totalPointsEarned =
                        totalPointsMax = totalPointsPercent = gradeScaleTotal = gradeScaleEarned = 0;

                    foreach (var gradeInput in gradeData)
                    {
                        var gradeInputNodes = gradeInput.ChildNodes;
                        gradeType          = gradeInputNodes[1].InnerText;
                        totalPointsEarned  = double.Parse(gradeInputNodes[2].InnerText);
                        totalPointsMax     = double.Parse(gradeInputNodes[3].InnerText);
                        totalPointsPercent = double.Parse(gradeInputNodes[4].InnerText.TrimEnd('%'));
                        gradeScaleTotal    = double.Parse(gradeInputNodes[5].InnerText);
                        gradeScaleEarned   = double.Parse(gradeInputNodes[6].InnerText);
                    }

                    var gradeInfo = new GradeInfo {
                        GradeType          = gradeType,
                        TotalPointsEarned  = totalPointsEarned,
                        TotalPointsMax     = totalPointsMax,
                        TotalPointsPercent = totalPointsPercent,
                        GradeScaleTotal    = gradeScaleTotal,
                        GradeScaleEarned   = gradeScaleEarned
                    };

                    var assignmentList = new List <Assignment>();

                    //gets all the assignments for a course
                    var assignmentTable = htmlNode.Descendants("table").FirstOrDefault(node =>
                                                                                       node.GetAttributeValue("class", "").Equals("sg-asp-table"));

                    foreach (var assignmentNode in assignmentTable.Descendants("tr").Where(node =>
                                                                                           node.GetAttributeValue("class", "").Equals("sg-asp-table-data-row")))
                    {
                        var assignment = new Assignment();
                        //Regex pattern = new Regex(".+:\\s");
                        var assignmentData = assignmentNode.ChildNodes[3].Descendants("a").FirstOrDefault()
                                             .Attributes["title"].Value;
                        var parsedAssignmentData = Regex.Replace(assignmentData, ".+:", "").Trim();


                        foreach (var(item, index) in new LineReader(() => new StringReader(parsedAssignmentData))
                                 .WithIndex())
                        {
                            switch (index)
                            {
                            case 0:
                                assignment.Title = item.Trim();
                                break;

                            case 1:
                                assignment.Name = FixAssignmentTitle(item.Trim());
                                break;

                            case 2:
                                assignment.Category = item.Trim();
                                break;

                            case 3:
                                var date = DateTime.Parse(item.Trim());
                                assignment.DueDate = date;
                                break;

                            case 4:
                                assignment.MaxPoints = double.Parse(item.Trim());
                                break;

                            case 5:
                                assignment.CanBeDropped = item.Contains("Y");
                                break;

                            case 6:
                                assignment.ExtraCredit = item.Contains("Y");
                                break;

                            case 7:
                                assignment.HasAttachments = item.Contains("Y");
                                break;
                            }
                        }

                        var score = assignmentNode.ChildNodes[5].InnerText.Trim();

                        assignment.Status = score switch {
                            "M" => AssignmentStatus.Missing,
                            "I" => AssignmentStatus.Incomplete,
                            "EXC" => AssignmentStatus.Excused,
                            "L" => AssignmentStatus.Late,
                            _ => AssignmentStatus.Upcoming
                        };

                        if (double.TryParse(score, out var points))
                        {
                            assignment.Status = AssignmentStatus.Complete;
                        }

                        assignment.Score = points.ToString(CultureInfo.CurrentCulture);
                        assignmentList.Add(assignment);
                    }

                    localCourseList.Add(new AssignmentCourse {
                        CourseName  = courseName, CourseId = courseId, CourseAverage = double.Parse(courseGrade),
                        Assignments = assignmentList, GradeInfo = gradeInfo, Teacher = teacherName,
                        RoomNumber  = teacherRoom
                    });
                }

                courseList.Add(localCourseList);
            }

            return(courseList);
        }