public/Get-FootballCompetitionPrediction.ps1

function Get-FootballCompetitionPrediction {
    <#
         # 231: Both Teams To Score Probability
         # 232: Half Time/Full Time Probability
         # 233: First Half Winner Probability
         # 234: Over/Under 1.5 Probability
         # 235: Over/Under 2.5 Probability
         # 236: Over/Under 3.5 Probability
         # 237: Fulltime Result Probability
         # 238: Team To Score First Probability
         # 239: Double Chance Probability
         # 240: Correct Score Probability
 
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DateMonth,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DateYear,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DaysToRun,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [Object]$FixtureList,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [Object]$FixtureListPrediction,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$Header,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $LeagueIdentifier = Get-LeagueIdentifier -Competition $Competition
            $DaysInMonth = [DateTime]::DaysInMonth($DateYear,$DateMonth)

            for ($Day = 1; $Day -le $DaysInMonth; $Day++) {

                if ($Day -gt $DaysToRun) {

                    continue

                } # if

                # Format the date to the correct format
                $Date = Get-Date -Year $DateYear -Month $DateMonth -Day $Day
                $DateFormatted = $Date.ToString("yyyy-MM-dd")

                # Get all the fixtures the date.
                $CompetitionFixtures = $FixtureList | Where-Object {$_.league_id -eq $LeagueIdentifier -and$_.starting_at -like "$DateFormatted*"}

                $Hash1 =@{
                    PSFunctionName = $($MyInvocation.MyCommand.Name)
                    Competition  = $Competition
                    FixtureCount = $($CompetitionFixtures.Count)
                    DaysInMonth = $DaysInMonth
                    Date = $DateFormatted
                }

                $Hash1 | Format-Table

                $FootballPredictionParams =@{
                    Header = $Headers
                    Token = $Token
                }

                if ($($PSBoundParameters.ContainsKey('FixtureListPrediction'))) {

                    $FootballPredictionParams.Add('FixtureListPrediction',$FixtureListPrediction)

                } # if

                # Skip when there are no fixtures for the date.
                if ($($CompetitionFixtures.Count) -lt 1) {

                    Write-Warning -Message "Date: $DateFormatted | Fixture count: $($CompetitionFixtures.Count)."
                    Write-Warning -Message "Skipping Date: $DateFormatted."

                }
                else {

                    # Wait random amounts of time for api calls.
                    $SecondsToWait = Get-Random -Minimum 2 -Maximum 4
                    Start-Sleep -Seconds $SecondsToWait

                    Get-FootballPrediction @FootballPredictionParams `
                                           -FixtureList $CompetitionFixtures `
                                           -Competition $Competition `
                                           -Date $DateFormatted `
                                           -Path $Path

                } # if

            } # foreach

        }
        catch {

            "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # trycatch

    } # process

} # function