Public/Get-AHStore.ps1
# .SYNOPSIS # Retrieves information about Albert Heijn stores function Get-AHStore { [CmdletBinding()] param ( [Parameter(Mandatory, ValueFromPipeLine, Position = 0)] [int[]]$ID ) process { $ID | ForEach-Object { $Url = "https://ah.nl/winkel/$_" $Content = Invoke-WebRequest -Uri $Url | Select-Object -ExpandProperty Content $OpeningHours = $Content | pup '.store-opening-hours_listItem__SaduL p json{}' --plain | ConvertFrom-Json | Select-Object -Skip 2 # Headers | Select-Object -ExpandProperty Text | ForEach-Object { $_ | Add-Member -NotePropertyName Day -NotePropertyValue ([System.DayOfWeek]((([Math]::Floor($Index++ / 3)) + 1) % 7)) -PassThru } | Group-Object -Property Day | ForEach-Object { $DayThisWeek = Get-DateFromWeekDay This $_.Name $DayNextWeek = Get-DateFromWeekDay Next $_.Name $TimesThisWeek = $_.Group | Select-Object -Skip 1 -First 1 $TimesNextWeek = $_.Group | Select-Object -Skip 2 -First 1 Get-OpeningHours -Date $DayThisWeek -Time $TimesThisWeek Get-OpeningHours -Date $DayNextWeek -Time $TimesNextWeek } [pscustomobject]@{ PSTypeName = 'UncommonSense.AH.Store' ID = $_ Url = $Url Name = ($Content | pup '.store-details_headingText__ynhSs text{}' --plain | ForEach-Object { $_.Trim() } | Where-Object { $_ }) -join ' ' Address = ($Content | pup '.store-address_addressItem__tHKZK:nth-of-type(1) p text{}' --plain | ForEach-Object { $_.Trim() } | Where-Object { $_ } ) -join ' ' PhoneNo = ($Content | pup '.store-address_addressItem__tHKZK:nth-of-type(3) p text{}' --plain | ForEach-Object { $_.Trim() } | Where-Object { $_ } ) -join ' ' OpeningHours = $OpeningHours | Sort-Object -Property From } } } } |