public override IEnumerable <SchoolProgram> FetchItems() { List <SchoolProgram> results = new List <SchoolProgram>(); TextInfo formatter = CultureInfo.CurrentCulture.TextInfo; if (this.Content == null) { return(results); } this.Content = this.Content.Replace("\n", String.Empty).Replace("\r", String.Empty); string programInfo = H2Regex.Match(this.Content).Value; MatchCollection matches = ProgramRegex.Matches(programInfo); foreach (Match match in matches) { SchoolProgram program = new SchoolProgram() { Name = formatter.ToTitleCase(SpaceRegex.Replace(match.Groups["name"].Value, " ").ToLowerInvariant()).Trim(' '), Description = SpaceRegex.Replace(AngleRegex.Replace(match.Groups["content"].Value.Replace("<br>", "|").Replace("<p>", "|"), String.Empty), " ").Trim('\n').Trim(' ').Trim('\n'), Campus = "UTSC" }; Console.WriteLine("UTSC Program: " + program.Name); results.Add(program); } return(results); }
public override IEnumerable <UTCourse> FetchItems() { List <UTCourse> results = new List <UTCourse>(); if (this.Content == null) { return(results); } this.Content = this.Content.Replace("\n", String.Empty).Replace("\r", String.Empty); MatchCollection matches = CourseRegex.Matches(this.Content); foreach (Match match in matches) { UTCourse course = new UTCourse() { Code = match.Groups["code"].Value, SemesterPrefix = match.Groups["prefix"].Value, Name = SpaceRegex.Replace(HttpUtility.HtmlDecode(match.Groups["name"].Value).Trim(' ').Trim(' '), " ") }; string[] properties = AngleRegex.Replace(match.Groups["content"].Value.Replace("<br>", "|"), String.Empty).Split('|'); string description = String.Empty; bool afterDescription = false; foreach (string property in properties) { if (property.Trim(' ').StartsWith("Prerequisite: ")) { course.Prerequisites = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Prerequisite: ".Length)), " "); afterDescription = true; } else if (property.Trim(' ').StartsWith("Exclusion: ")) { course.Exclusions = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Exclusion: ".Length)), " "); afterDescription = true; } else if (property.Trim(' ').StartsWith("Breadth Requirement: ")) { course.Exclusions = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Breadth Requirement: ".Length)), " "); afterDescription = true; } else if (property.Trim(' ').StartsWith("Corequisite: ")) { course.Corequisites = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Corequisite: ".Length)), " "); afterDescription = true; } else if (!afterDescription) { description += property; } } course.Description = description; course.Department = SpaceRegex.Replace(HttpUtility.HtmlDecode(description), " ").Trim(' '); course.Department = UrlRegex.Match(this.Url).Groups["name"].Value.Replace("_", " "); results.Add(course); //Console.WriteLine("UTSC Course: " + course.Abbr); } return(results); }