public static UClass ParseClass(IHtmlTableRowElement classRow, int classYear = 0, USemester classSemester = USemester.Unknown) { int courseId = int.Parse(classRow.QuerySelector <IHtmlSpanElement>(slc_classId).TextContent); string courseName = classRow.QuerySelector <IHtmlSpanElement>("td>span[id*=CourseName]").TextContent; string classInstructor = classRow.QuerySelector <IHtmlSpanElement>("td>span[id*=Instructor]").TextContent; int classSection = int.Parse(classRow.QuerySelector <IHtmlSpanElement>(slc_classSection).TextContent); string classDaysString = classRow.QuerySelector <IHtmlSpanElement>("td>span[id*=Day]").TextContent; DayOfWeek[] classDays = DayOfWeekConverter.ToDays(classDaysString).ToArray(); var(classStartTime, classEndTime) = ParseClassTime(classRow.OuterHtml); int.TryParse(classRow.QuerySelector <IHtmlSpanElement>("td>span[id*=MaxStNo]")?.TextContent, out int classCapacity); int.TryParse(classRow.QuerySelector <IHtmlSpanElement>("td>span[id*=RegStNo]")?.TextContent, out int classRegisterdStudentsCount); //To detecet Labs int classFinancialHours = (int)((classDays.Length == 1 ? 1 : (classEndTime - classStartTime).TotalHours) * classDays.Length); classInstructor = classInstructor.Trim(); courseName = courseName.Trim(); return(new UClass(course: new UCourse(courseId, classFinancialHours, courseName), instructorName: classInstructor, days: classDays, startTime: classStartTime, endTime: classEndTime, section: classSection, capacity: classCapacity, numberOfRegisteredStudents: classRegisterdStudentsCount)); }
private async IAsyncEnumerable <R4UCard> ParseCards(IHtmlTableRowElement row, WikiSetContext context) { var cardLink = row.Cells[1].ChildNodes[0] as IHtmlAnchorElement; Log.Information("Following link: {link}", cardLink.Href); var cardDocument = await new Uri(cardLink.Href).DownloadHTML(("Referer", context.URL)).WithRetries(10); var rawMainInfoBox = cardDocument.QuerySelector <IHtmlTableElement>(".info-main > table") // .Rows .Select(x => (x.Cells[0].TextContent, x.Cells[1])) .ToDictionary(p => p.Item1.Trim().ToLower(), p => p.Item2) ; var mainInfoBox = rawMainInfoBox.ToDictionary(p => p.Key, p => p.Value.TextContent.Trim()); var extraInfoBox = cardDocument.QuerySelector(".info-extra") // .ChildNodes // .Where(x => x is IHtmlTableElement) // .Select(x => x as IHtmlTableElement) // .Select(t => (t.Rows[0].Cells[0].TextContent, t.Rows[1].Cells[0].GetInnerText())) // .ToDictionary(p => p.Item1.Trim().ToLower(), p => p.Item2.Trim()); var cardContext = new WikiCardContext { ExtraInfoBox = extraInfoBox, MainInfoBox = mainInfoBox, RawMainInfoBox = rawMainInfoBox }; Log.Debug("Main Info Box: @{mainInfoBox}", mainInfoBox); Log.Debug("Extra Info Box: @{extraInfoBox}", extraInfoBox); var originalCard = await ParseOriginalCard(cardContext, context); var serialRarityPairs = serialMatcher.Matches(extraInfoBox["card set(s)"]) .Where(m => m.Groups[2].Value == context.SetData["prefix"]) .Select(m => (Serial: m.Groups[1].Value, Rarity: m.Groups[3].Value)) .ToList(); var originalSerialRarity = serialRarityPairs.First(p => nonFoilRarities.Contains(p.Rarity)); serialRarityPairs.Remove(originalSerialRarity); originalCard.Serial = originalSerialRarity.Serial; originalCard.Rarity = originalSerialRarity.Rarity; yield return(originalCard); foreach (var foilSRP in serialRarityPairs) { var foilCard = originalCard.Clone(); foilCard.Rarity = foilSRP.Rarity; foilCard.Serial = foilSRP.Serial; foilCard.NonFoil = originalCard; yield return(foilCard); } Log.Debug($"Original Card: {JsonSerializer.Serialize(originalCard)}"); //await Task.Delay(60000); yield break; }
private static void AssertTableRow(IHtmlTableRowElement row, string larId, string qualificationTitle, int qualificationId, int venueId) { row.Cells[0].TextContent.Should().Be(larId); row.Cells[1].TextContent.Should().Be(qualificationTitle); var deleteCell = row.Cells[2].Children[0] as IHtmlAnchorElement; deleteCell.TextContent.Should().Be("Remove qualification"); deleteCell.PathName.Should().Be($"/remove-qualification/{venueId}/{qualificationId}"); }
private static void AssertTableRow(IHtmlTableRowElement row, string ukprn, string name, string cdfProvider, int providerId) { row.Cells[0].TextContent.Should().Be(ukprn); row.Cells[1].TextContent.Should().Be(name); row.Cells[2].TextContent.Should().Be(cdfProvider); var editCell = row.Cells[3].Children[0] as IHtmlAnchorElement; editCell.TextContent.Should().Be("Edit SQL Search Provider's details"); editCell.PathName.Should().Be($"/provider-overview/{providerId}"); }
private static void AssertTableRow(IHtmlTableRowElement row, string postcode, string numberOfQualifications, string helpFindingPlacements, int venueId, int providerId) { row.Cells[0].TextContent.Should().Be(postcode); row.Cells[1].TextContent.Should().Be(numberOfQualifications); row.Cells[2].TextContent.Should().Be(helpFindingPlacements); var editCell = row.Cells[3].Children[0] as IHtmlAnchorElement; editCell.TextContent.Should().Be("Edit this venue"); editCell.PathName.Should().Be($"/venue-overview/{venueId}"); editCell.Search.Should().Be($"?providerId={providerId}"); }
private static void AssertTableRow(IHtmlTableRowElement row, string employerName, string lastUpdated, int opportunityId) { row.Cells[0].TextContent.Should().Be(employerName); row.Cells[1].TextContent.Should().Be(lastUpdated); var rowEditCell = row.Cells[2].Children[0] as IHtmlAnchorElement; rowEditCell.Text.Should().Be("Edit this employer’s opportunities"); rowEditCell.PathName.Should().Be($"/employer-opportunities/{opportunityId}-0"); var rowDeleteCell = row.Cells[3].Children[0] as IHtmlAnchorElement; rowDeleteCell.Text.Should().Be("Delete this employer’s opportunities"); rowDeleteCell.PathName.Should().Be($"/confirm-remove-employer/{opportunityId}"); }
private static void AssertTableRow(IHtmlTableRowElement row, string workplace, string jobRole, string studentsWanted, string providers, int opportunityItemId) { row.Cells[1].TextContent.Should().Be(workplace); row.Cells[2].TextContent.Should().Be(jobRole); row.Cells[3].TextContent.Should().Be(studentsWanted); row.Cells[4].TextContent.Should().Be(providers); var editCell = row.Cells[5].Children[0] as IHtmlAnchorElement; editCell.Text.Should().Be("Edit"); editCell.PathName.Should().Be($"/check-answers/{opportunityItemId}"); var deleteCell = row.Cells[6].Children[0] as IHtmlAnchorElement; deleteCell.Text.Should().Be("Delete"); deleteCell.PathName.Should().Be($"/remove-opportunity/{opportunityItemId}"); }
private static (int ClassId, string ClassRegistrationEventTarget) ParseClassIdAndRegistrationEventTarget(IHtmlTableRowElement classRow) { int courseId = int.Parse(classRow.QuerySelector <IHtmlSpanElement>(slc_classId).TextContent); int classSection = int.Parse(classRow.QuerySelector <IHtmlSpanElement>(slc_classSection).TextContent); string registrationAnchorHref = classRow.QuerySelector <IHtmlAnchorElement>("a[id*=btnAddCourse]").Href; int hrefFirstQuoteIndex = registrationAnchorHref.IndexOf('\''), hrefSecondQuoteIndex = registrationAnchorHref.IndexOf('\'', hrefFirstQuoteIndex + 1); string registrationEventTarget = registrationAnchorHref.Substring(hrefFirstQuoteIndex + 1, hrefSecondQuoteIndex - hrefFirstQuoteIndex - 1); return(UClass.Identify(courseId, classSection), registrationEventTarget); }
private bool IsRowCompatible(IHtmlTableRowElement row) { return(row.Cells[1].ChildNodes[0] is IHtmlAnchorElement anchor && anchor.Relation != "nofollow"); }
private static IEnumerable <IHtmlTableCellElement> RowChildren(IHtmlTableRowElement re) { return(re.Children <IHtmlTableCellElement>() .Value.SelectMany(child => Linq.Range(child.ColumnSpan), (child, _) => child)); }