public/Invoke-AutomatedProcessHistoricalFootballFixtureMedia.ps1
function Invoke-AutomatedProcessHistoricalFootballFixtureMedia { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$BucketName, [Parameter(Mandatory=$true)] [ValidateSet('australia','europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')] [string]$Continent, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$PageId, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory=$true)] [ValidateSet('facebook','instagram')] [string]$Platform, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$SMToken, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$StartDate ) process{ $ErrorActionPreference = 'Stop' try { $ContentToPost =@('match','goals','corners') $Competions = Select-FootballCompetition -Continent $Continent $Competions | Format-Table $Competions.GetEnumerator() | ForEach-Object -Process { $Competition = $_.key Write-Warning "Processing: $Competition" $CompetitionDate = (Get-ChildItem -Path "$Path\sportsmonk-results\$Competition" -ErrorAction Stop).Name $StartProcessing = $false foreach ($Date in $CompetitionDate) { $DateToUse = Get-Date -Date $Date $StartDateToUse = Get-Date -Date $StartDate if ($DateToUse -gt $StartDateToUse) { $StartProcessing = $true } # if if ($StartProcessing) { foreach ($Content in $ContentToPost) { # Convert png to jpg Convert-FootballFixtureMediaFile -Competition $Competition -Date $Date -Content $Content -Path $Path # Copy to central location Copy-FootballFixtureConvertedMedia -SourcePath "$Path\fixture-artifact\working-set\$Competition\$Date" -TargetPath $Path # Sync to S3 bucket aws s3 sync "$Path\fixture-artifact\instagram" "s3://$BucketName/instagram" --acl public-read if ($Platform -eq 'facebook') { $FacebookPost = Confirm-ProcessedFootballFixtureMedia -Competition $Competition -Date $Date -Content $Content -Endpoint fbpost -Path $Path $FacebookStory = Confirm-ProcessedFootballFixtureMedia -Competition $Competition -Date $Date -Content $Content -Endpoint fbstory -Path $Path if ($($FacebookPost.Count) -ge 1) { Invoke-AutomatedFacebookPostWithPhoto -Token $SMToken -Competition $Competition -Date $Date -Content $Content -PageId $PageId -Post -Path $Path } # if if ($($FacebookStory.Count) -ge 1) { Invoke-AutomatedFacebookStoryWithPhoto -Token $SMToken -Competition $Competition -Date $Date -Content $Content -PageId $PageId -Post -Path $Path } # if } # if if ($Platform -eq 'instagram') { $InstagramPost = Confirm-ProcessedFootballFixtureMedia -Competition $Competition -Date $Date -Content $Content -Endpoint instagram -Path $Path $InstagramStory = Confirm-ProcessedFootballFixtureMedia -Competition $Competition -Date $Date -Content $Content -Endpoint instagram-story -Path $Path if ($($InstagramPost.Count) -ge 1) { Invoke-AutomatedInstagramSingleMediaPost -Token $SMToken -BucketName $BucketName -Competition $Competition -Date $Date -Content $Content -PageId $PageId -Post -Path $Path } # if if ($($InstagramStory.Count) -ge 1) { Invoke-AutomatedInstagramSingleMediaStoryPost -Token $SMToken -BucketName $BucketName -Competition $Competition -Date $Date -Content $Content -PageId $PageId -Post -Path $Path } # if } # if } # foreach } # foreach } # if } # foreach-object } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # fixture |