Skip to content

Commit

Permalink
make koki more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinschumacher committed May 31, 2024
1 parent 92a9780 commit cf54b60
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Scrapers/KoKiScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using kinohannover.Models;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using System.Web;
using TMDbLib.Client;

namespace kinohannover.Scrapers
Expand Down Expand Up @@ -40,7 +41,18 @@ public async Task ScrapeAsync()
foreach (var hr in hrs)
{
var paragraphs = hr.SelectNodes(_paragraphSelection);
var date = DateOnly.Parse(paragraphs.First().InnerText);
DateOnly date;
string dateText = string.Empty;
try
{
dateText = HttpUtility.HtmlDecode(paragraphs.First().InnerText).Trim();
date = DateOnly.Parse(dateText, culture.DateTimeFormat);
}
catch (Exception)
{
logger.LogError("Failed to parse date {dateText}", dateText);
continue;
}

var movieParagraph = paragraphs.Skip(1).First();
var movieElements = movieParagraph.SelectNodes(_immediateTextChildren).Where(e => e.InnerText.Contains("Uhr"));
Expand All @@ -49,7 +61,18 @@ public async Task ScrapeAsync()
var timeMatches = ShowTimeRegex().Match(movieElement.InnerText);
if (!timeMatches.Success)
continue;
var time = TimeOnly.Parse(timeMatches.Groups[1].Value);
TimeOnly time;
string timeText = string.Empty;
try
{
timeText = HttpUtility.HtmlDecode(timeMatches.Groups[1].Value).Trim();
time = TimeOnly.Parse(timeMatches.Groups[1].Value);
}
catch (Exception)
{
logger.LogError("Failed to parse time {timeText}", timeMatches.Groups[1].Value);
continue;
}
if (movieElement.NextSibling == null || movieElement.NextSibling.Name != "a")
continue;
var showTimeLink = movieElement.NextSibling.Attributes["href"].Value;
Expand Down

0 comments on commit cf54b60

Please sign in to comment.