Public/Get-FilmtheaterHilversum.ps1
function Get-FilmtheaterHilversum { [CmdletBinding()] param() $DutchCulture = Get-Culture 'nl-NL' $Today = Get-Date -Hour 0 -Minute 0 -Second 0 -Millisecond 0 $Tomorrow = $Today.AddDays(1) Invoke-WebRequest -Uri https://www.filmtheaterhilversum.nl/films/ ` | Select-Object -ExpandProperty Links ` | Where-Object Href -Like 'https://filmtheaterhilversum.nl/film/*' | Select-Object -ExpandProperty HRef ` | ForEach-Object { Write-Verbose "Processing movie url $($_)" $Url = $_ $Document = ConvertTo-HtmlDocument -Uri $Url $Title = $Document | Select-HtmlNode -CssSelector 'h1' | Get-HtmlNodeText Write-Verbose "- Title is $Title" $Body = $Document | Select-HtmlNode -CssSelector '.content p strong' | Get-HtmlNodeText Write-Verbose "- Body is $Body" $Document | Select-HtmlNode -CssSelector '.movie-time' -All | ForEach-Object { $CurrentMovieTime = $_ $ScreenDay = $CurrentMovieTime | Select-HtmlNode -CssSelector '.movie-screenday' | Get-HtmlNodeText Write-Verbose "- Screen day as text '$($ScreenDay)'" $ScreenDay = switch -regex ($ScreenDay) { 'Vandaag' { $Today; break; } 'Morgen' { $Tomorrow; break; } '^\w{2}\s(\d{1,2})\s(\w{3})$' { # It seems that the nl-NL culture expects a period after the abbreviated Dutch month name # on Ubuntu in GitHub actions, but not on MacOS? Moved away from DateTime.ParseExact to # a more involved but hopefully more robust way of parsing. $Day = [int]::Parse($Matches[1]) $Month = switch($Matches[2]) { 'jan' { 1; break; } 'feb' { 2; break; } 'mrt' { 3; break; } 'apr' { 4; break; } 'mei' { 5; break; } 'jun' { 6; break; } 'jul' { 7; break; } 'aug' { 8; break; } 'sep' { 9; break; } 'okt' { 10; break; } 'nov' { 11; break; } 'dec' { 12; break; } } Get-Date -Day $Day -Month $Month -Hour 0 -Minute 0 -Second 0 -Millisecond 0 } } Write-Verbose "- Screen day as date $($ScreenDay)" if ($ScreenDay -lt $Today) # assume next year if day/month before today (end of December/start of January) { $ScreenDay = $ScreenDay.AddYears(1) } Write-Verbose "- Corrected screen day '$($ScreenDay.ToShortDateString())'" $CurrentMovieTime | Select-HtmlNode -CssSelector '.movie-timeblock' -All | ForEach-Object { $_ | Get-HtmlNodeText } | ForEach-Object { Write-Verbose "- Time '$($_)'"; $_ } | ForEach-Object { [TimeSpan]::ParseExact("$($_):00", 'g', $DutchCulture) } | ForEach-Object { $ScreenDay.Add($_) } } | ForEach-Object { [PSCustomObject]@{ PSTypeName = 'UncommonSense.Cinema.Film' Url = $Url Date = $_ Title = $Title Body = $Body } } } } |