Ejemplo n.º 1
0
        public override IEnumerable <string> FetchItems()
        {
            if (this.Content == null)
            {
                return(new List <string>());
            }
            string tableContent = this.Content.Replace("\n", String.Empty);

            tableContent = tableContent.Replace("\r", String.Empty);
            tableContent = TableRegex.Match(tableContent).Value;
            return(CodeRegex.Matches(tableContent).Cast <Match>().Select(x => x.Value));
        }
Ejemplo n.º 2
0
        public override IEnumerable <UTCourse> FetchItems()
        {
            List <UTCourse> results = new List <UTCourse>();

            this.Content = this.Content.Replace("\n", String.Empty).Replace("\r", String.Empty);
            MatchCollection matches = DetailRegex.Matches(this.Content);

            foreach (Match match in matches)
            {
                string[] properties = AngleRegex.Replace(BrRegex.Replace(match.Value.Replace("</p>", "|"), "|"), String.Empty).Split('|');
                Match    codeMatch  = CodeRegex.Match(match.Value);

                UTCourse course = new UTCourse()
                {
                    Code           = codeMatch.Value.Replace(" ", String.Empty),
                    SemesterPrefix = codeMatch.Groups["prefix"].Value,
                    Semester       = codeMatch.Groups["semester"].Value,
                    Description    = "",
                    Corequisites   = match.Groups["section"].Value
                };

                foreach (string property in properties)
                {
                    if (property.Length > course.Description.Length)
                    {
                        course.Description = HttpUtility.HtmlDecode(property.Trim(' '));
                    }
                    if (property.Trim(' ').StartsWith("Breadth"))
                    {
                        course.BreadthRequirement = property.Trim(' ').Substring("Breadth category: ".Length);
                    }
                }
                results.Add(course);
            }
            return(results);
        }
Ejemplo n.º 3
0
        public IEnumerable <UTCourse> FetchItems()
        {
            List <UTCourse> results = new List <UTCourse>();

            if (this.Content == null)
            {
                return(results);
            }

            this.Content = this.Content.Replace("\r\n", String.Empty);
            this.Content = this.Content.Replace("\n", String.Empty);
            MatchCollection matches = TableRegex.Matches(this.Content);

            foreach (var match in matches)
            {
                var line      = match.ToString();
                var codeMatch = CodeRegex.Match(line);
                var secMatch  = SectionRegex.Match(line);
                if (codeMatch.Success && !line.Contains("<br>") && line.Contains("<b>"))
                {
                    // New course
                    string   courseName = AngleRegex.Replace(line, String.Empty);
                    UTCourse course     = new UTCourse()
                    {
                        Code           = codeMatch.Value.Substring(0, 6),
                        Name           = courseName.Substring(12),
                        Semester       = codeMatch.Value.Substring(8, 1),
                        SemesterPrefix = codeMatch.Value.Substring(6, 2),
                        Campus         = "UTSC"
                    };
                    results.Add(course);
                    Console.Write("{0}UTSC Course: {1} ", Environment.NewLine, course.Abbr);
                }
                else if (secMatch.Success)
                {
                    // New section
                    if (results.Count > 0)
                    {
                        var lastCourse = results.Last();
                        line = line.Replace("</td>", "|");
                        line = AngleRegex.Replace(line, String.Empty);
                        var parts = line.Split('|');
                        if (parts.Length >= 6)
                        {
                            var sectionName           = parts[0];
                            var sectionDayRaw         = parts[1];
                            var sectionTimeStart      = parts[2];
                            var sectionTimeEnd        = parts[3];
                            var sectionLocation       = parts[4].Replace(" ", String.Empty);
                            var sectionInstructor     = parts[5];
                            UTSCCourseSection section = new UTSCCourseSection()
                            {
                                Name       = sectionName,
                                Location   = sectionLocation,
                                Instructor = sectionInstructor,
                                Time       = String.Join(" ", sectionDayRaw, sectionTimeStart, sectionTimeEnd)
                            };
                            lastCourse.Sections.Add(section);
                            Console.Write(" {0} ", section.Name);
                        }
                    }
                }
                else if (line.Contains("MO") ||
                         line.Contains("TU") ||
                         line.Contains("WE") ||
                         line.Contains("TH") ||
                         line.Contains("FR"))
                {
                    // New meet time.
                    if (results.Count > 0)
                    {
                        var lastCourse = results.Last();
                        if (lastCourse.Sections.Count > 0)
                        {
                            var lastSection = lastCourse.Sections.Last();

                            line = line.Replace("</td>", "|");
                            line = AngleRegex.Replace(line, String.Empty);
                            var parts = line.Split('|');
                            if (parts.Length >= 6)
                            {
                                var sectionName       = parts[0];
                                var sectionDayRaw     = parts[1];
                                var sectionTimeStart  = parts[2];
                                var sectionTimeEnd    = parts[3];
                                var sectionLocation   = parts[4].Replace(" ", String.Empty);
                                var sectionInstructor = parts[5];
                                lastSection.Time     = String.Join(" ", lastSection.Time, sectionDayRaw, sectionTimeStart, sectionTimeEnd);
                                lastSection.Location = String.Join(" ", lastSection.Location, sectionLocation);
                            }
                        }
                    }
                }
                else
                {
                    continue;
                }
            }
            return(results);
        }