public/New-SocialMediaContent.ps1
function New-SocialMediaContent { <# .EXAMPLE New-SocialMediaContent -Competition chn-superleague -Date 2025-04-27 -Content match -Path C:\sportsmonk #> [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Competition, [Parameter(Mandatory=$false)] [ValidateSet('corners','goals','match','outcomes')] [string]$Content, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Date, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory=$false)] [switch]$Prediction, [Parameter(Mandatory=$false)] [switch]$PredictionReview, [Parameter(Mandatory=$false)] [ValidateSet('btts','csp','htft','ag05','ag15','ag25','ag35','hg05','hg15','hg25','hg35','ou15','ou25','ou35','ouc4','ouc5','ouc6','ouc7','ouc8','ouc9','ttsf','dbch','ftrt','fhwn')] [string]$Type ) process{ $ErrorActionPreference = 'Stop' try { switch ($Content) { 'outcomes' { $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\outcomes_post.txt" } default { $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\social_media.txt" } } # switch # Convert string to DateTime object $DateObject = [DateTime]::ParseExact($Date, 'yyyy-MM-dd', $null) # Format the DateTime object to the desired format 2025-04-06 becomes 06-04-2025 $FormattedDate = $DateObject.ToString('dd-MM-yyyy') # Get Competition name $CompetitionName = Get-Competition -Name $Competition # Set results path $ResultPath = "$Path\sportsmonk-results\$Competition\$Date\$Competition-$Date.csv" # Test paths exist $TmplatePathExists = Test-Path -Path $TemplatePath $ResultPathExists = Test-Path -Path $ResultPath if ($TmplatePathExists -and $ResultPathExists -and $Content -eq 'outcomes') { $Template = Get-Content -Path $TemplatePath -Raw -ErrorAction Stop $Template = $Template.Replace('<CompetitionName>',$CompetitionName) $Template = $Template.Replace('<FormattedDate>',$FormattedDate) $Template } # if if ($PredictionReview) { $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\social_media_prediciton_review" $TmplatePathExists = Test-Path -Path $TemplatePath if ($TmplatePathExists) { $Template = Get-Content -Path $TemplatePath -Raw -ErrorAction Stop $Template = $Template.Replace('<CompetitionName>',$CompetitionName) $Template = $Template.Replace('<FormattedDate>',$FormattedDate) $Template } # if } # if if ($TmplatePathExists -and $ResultPathExists -and $Content -ne 'outcomes' -and !$PredictionReview -or $Prediction) { if ($Prediction -and $Type -ne 'csp') { # Set the market type $MarketType = Get-MarketTypePercentageColumn -Type $Type # Set the predictions path $PredictionsPath = "$Path\sportsmonk-predictions\$Competition\$Date\$Competition-$($MarketType.Identifier)-$Date.csv" # Set the template path $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\social_media_predictions.txt" # Import the fixtures $Fixtures = Import-Csv -Path $PredictionsPath -ErrorAction Stop } elseif ($Prediction -and $Type -eq 'csp') { # Set the predictions path $PredictionsPath = "$Path\sportsmonk-predictions\$Competition\$Date\$Competition-240-$Date.csv" # Import the fixtures $CSP = Import-Csv -Path $PredictionsPath -ErrorAction Stop $Fixtures = Get-CorrectScoreProbability -Competition $Competition -Date $Date -Path "$Path\sportsmonk-predictions" # Set the template path $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\social_media_csp_predictions.txt" } else { $Fixtures = Import-Csv -Path $ResultPath -ErrorAction Stop } # if # Set count $FixtureCount = 0 foreach ($Fixture in $Fixtures) { $Template = Get-Content -Path $TemplatePath -Raw $Template = $Template.Replace('<CompetitionName>',$CompetitionName) $Template = $Template.Replace('<FixtureName>',$($Fixture.FixtureName)) if ($Prediction) { #$Template = $Template.Replace('<Content>',$($Fixture.TypeName)) #$Template = $Template.Replace('<FormattedDate>',$($Fixture.StartingAt)) switch ($Type) { 'btts' { $String = "Yes ( $($Fixture.Yes) ) - No ( $($Fixture.No) )" $Template = $Template.Replace('<String>',$String) $Template = $Template.Replace('<Content>',$($Fixture.TypeName)) $Template = $Template.Replace('<FormattedDate>',$($Fixture.StartingAt)) } 'csp' { $FixtureToUse = $Fixtures | Where-Object {$_.FixtureId -eq $($Fixture.FixtureId)} | Sort-Object -Property Percentage -Descending $FixtureSchedule = $CSP | Where-Object {$_.FixtureId -eq $($Fixture.FixtureId)} #$FixtureSchedule | Format-Table $Template = $Template.Replace('<Content>',$($FixtureSchedule.TypeName)) $Template = $Template.Replace('<FormattedDate>',$($FixtureSchedule.StartingAt)) $String1 = "$($FixtureToUse[0].Score) - $($FixtureToUse[0].Percentage) - $($FixtureToUse[0].OutCome)" $String2 = "$($FixtureToUse[1].Score) - $($FixtureToUse[1].Percentage) - $($FixtureToUse[1].OutCome)" $String3 = "$($FixtureToUse[2].Score) - $($FixtureToUse[2].Percentage) - $($FixtureToUse[2].OutCome)" $String4 = "$($FixtureToUse[3].Score) - $($FixtureToUse[3].Percentage) - $($FixtureToUse[3].OutCome)" $String5 = "$($FixtureToUse[4].Score) - $($FixtureToUse[4].Percentage) - $($FixtureToUse[4].OutCome)" $String6 = "$($FixtureToUse[5].Score) - $($FixtureToUse[5].Percentage) - $($FixtureToUse[5].OutCome)" $String7 = "$($FixtureToUse[6].Score) - $($FixtureToUse[6].Percentage) - $($FixtureToUse[6].OutCome)" $String8 = "$($FixtureToUse[7].Score) - $($FixtureToUse[7].Percentage) - $($FixtureToUse[7].OutCome)" $Template = $Template.Replace('<String1>',$String1) $Template = $Template.Replace('<String2>',$String2) $Template = $Template.Replace('<String3>',$String3) $Template = $Template.Replace('<String4>',$String4) $Template = $Template.Replace('<String5>',$String5) $Template = $Template.Replace('<String6>',$String6) $Template = $Template.Replace('<String7>',$String7) $Template = $Template.Replace('<String8>',$String8) } {$_ -eq 'ou15' -or $_ -eq 'ou25'} { $String = "Yes ( $($Fixture.Yes) ) - No ( $($Fixture.No) )" $Template = $Template.Replace('<Content>',"Goals - $($Fixture.TypeName)") $Template = $Template.Replace('<String>',$String) $Template = $Template.Replace('<FormattedDate>',$($Fixture.StartingAt)) } 'dbch' { $String = "DrawHome ( $($Fixture.DrawHome) ) - DrawAway ( $($Fixture.DrawAway) ) - HomeAway ( $($Fixture.HomeAway) )" $Template = $Template.Replace('<String>',$String) $Template = $Template.Replace('<Content>',$($Fixture.TypeName)) $Template = $Template.Replace('<FormattedDate>',$($Fixture.StartingAt)) } 'fhwn' { $String = "Home ( $($Fixture.Home) ) - Away ( $($Fixture.Away) ) - Draw ( $($Fixture.Draw) )" $Template = $Template.Replace('<String>',$String) $Template = $Template.Replace('<Content>',$($Fixture.TypeName)) $Template = $Template.Replace('<FormattedDate>',$($Fixture.StartingAt)) } } # switch if ($FixtureCount -ge 2) { continue } # if # Return the template $Template # Blank line for out-file "" } else { $Template = $Template.Replace('<Content>',$Content) $Template = $Template.Replace('<FormattedDate>',$FormattedDate) # Return the template $Template # Blank line for out-file "" } # if # Implement fixture count $FixtureCount ++ } # foreach } # if } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # try catch } # process } # function |