public static List <GenericGroupedCollection <string, string> > GetImportantDates(string page) { var headerMatches = Regex.Matches(page, @"<h4>(S|s)(.*?)<\/h4><p><strong>(.*?)<\/strong>(.*?)<(.*?)\/p>", RegexOptions.Multiline); string[] tableHeaders = { "Dni rektorskie: ", "Przerwa świąteczna:", "Sesja egzaminacyjna:", "Sesja poprawkowa:" }; var dic = new List <GenericGroupedCollection <string, string> >(); if (headerMatches.Count == 2) { var semsters = new List <string>() { page.Substring(headerMatches[0].Index, headerMatches[1].Index - headerMatches[0].Index), page.Substring(headerMatches[1].Index) }; for (int i = 0; i < 2; i++) { var result = new GenericGroupedCollection <string, string>(headerMatches[i].Groups[1].ToString() + headerMatches[i].Groups[2].ToString()); result.Add(string.Format("{0} {1}", headerMatches[i].Groups[3].ToString(), headerMatches[i].Groups[4].ToString().Replace("r.", string.Empty).Replace(" r.", string.Empty))); var first = true; foreach (var head in tableHeaders) { var match = Regex.Match(semsters[i], string.Format(@"<strong>{0}<\/strong>(.*?)<", head), RegexOptions.Multiline); if (first) { var differentDaysString = semsters[i].Substring((headerMatches[i].Groups[4].Index + headerMatches[i].Groups[4].Length) - headerMatches[i].Index, match.Index); var daysMatch = Regex.Matches(differentDaysString.Replace("\n", string.Empty), @"r>(.+?)(<\/p|<b)"); var dayString = ""; foreach (Match day in daysMatch) { dayString += day.Groups[1].ToString().Replace("\r", string.Empty) + "\n"; } result.Add(string.Format("Zmiany dni: {0}", dayString.Replace("r.", string.Empty).Replace(" r.", string.Empty).Replace(" , ", ", "))); first = false; } if (match != null) { result.Add(string.Format("{0} {1}", head, match.Groups[1].ToString().Replace("r.", string.Empty).Replace(" r.", string.Empty).Replace(" , ", ", "))); } } dic.Add(result); } } return(dic); }
public static Employee GetEmployeeDetails(string page, Employee employee) { page = page.Replace("\n", string.Empty); var employeeDetailsMatch = Regex.Match(page, @"<tr><th>pokój<\/th><td>(.*?)<\/td><\/tr>(.*?)<h3>Konsultacje:<\/h3><p>(.*?)<\/p>(.*?)<div class=""byWeekDays"">(.*?)<\/div>", RegexOptions.Multiline); if (employeeDetailsMatch == null) { throw new Exception(); } employee.Room = new Xamarin.Forms.FormattedString(); employee.Room.Spans.Add(new Xamarin.Forms.Span() { Text = "Pokój: ", FontAttributes = Xamarin.Forms.FontAttributes.Bold }); employee.Room.Spans.Add(new Xamarin.Forms.Span() { Text = employeeDetailsMatch.Groups[1].ToString().Trim(' ').Replace("\t", string.Empty) }); var consults = employeeDetailsMatch.Groups[3].ToString().Trim(' ').Replace("\t", string.Empty); if (consults.Length > 0) { employee.Consults = consults.ToUpper()[0] + consults.Substring(1); } else { employee.Consults = "Brak danych"; } var weekByDays = employeeDetailsMatch.Groups[5].ToString(); var daysMatch = Regex.Matches(weekByDays, @"<h3>(.*?)<\/h3><ul>(.*?)<\/ul>"); var dict = new List <GenericGroupedCollection <string, string> >(); foreach (Match match in daysMatch) { var day = match.Groups[1].ToString(); if (day == "Poniedzialek") { day = "Poniedziałek"; } if (day == "Sroda") { day = "Środa"; } if (day == "Piatek") { day = "Piątek"; } var x = new GenericGroupedCollection <string, string>(day); var classesMatch = Regex.Matches(match.Groups[2].ToString(), @"<li><span class=""time"">(.*?)</span><span class=""name"">(.*?)</span><span class=""type"">(.*?)</span><span class=""classroom"">(.*?)</span></li>", RegexOptions.Multiline); foreach (Match classMatch in classesMatch) { var hours = classMatch.Groups[1].ToString().Trim(' ').Replace("\t", string.Empty); var name = classMatch.Groups[2].ToString().Trim(' ').Replace("\t", string.Empty); var type = classMatch.Groups[3].ToString().Trim(' ').Replace("\t", string.Empty).Replace("–", string.Empty); if (type.Length == 0) { type = "Brak danych"; } var classRoom = classMatch.Groups[4].ToString().Trim(' ').Replace("\t", string.Empty); x.Add(string.Format("{0} {1}, {2} s.{3}", hours, name, type, classRoom)); } dict.Add(x); } employee.WeekPlan = dict; return(employee); }