public/New-FootballCompetitionStasticFile.ps1
function New-FootballCompetitionStasticFile { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateSet('europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')] [string]$Continent, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory=$true)] [ValidateSet('cards','corners','defeat-percentage','draw-percentage','win-percentage')] [string]$Type ) process{ $ErrorActionPreference = 'Stop' try { $PathToUse = "$Path\fixture-artifact\stage-statistic\$Continent" $FilesToProcess = Get-ChildItem -Path $PathToUse -Recurse -File -ErrorAction Stop | Where-Object {$_.Name -like "*$Type*" -and $_.Name -notlike "$Continent-$Type*"} foreach ($File in $FilesToProcess) { $PSObject = [PSCustomObject]@{} # Microsoft.PowerShell.Core\FileSystem::C:\sportsmonk\fixture-artifact\stage-statistic\europe-uk\2024\193-cards $ParentPath = $($File.PSParentPath).Split('::')[1] $Filecontent = Import-Csv -Path $($File.FullName) $Filecontent.PSObject.Properties | ForEach-Object -Process { if ($_.Name -like 'v_*') { Write-Warning -Message "Proccesing: $($_.Name), $($_.Value)" $PSObject | Add-Member -MemberType NoteProperty -Name $($_.Name) -Value $($_.Value) } # if if ($_.Name -eq 's_league_id') { Write-Warning -Message "Proccesing: $($_.Name), $($_.Value)" $PSObject | Add-Member -MemberType NoteProperty -Name $($_.Name) -Value $($_.Value) } # if if ($_.Name -eq 't_name') { Write-Warning -Message "Proccesing: $($_.Name), $($_.Value)" $PSObject | Add-Member -MemberType NoteProperty -Name $($_.Name) -Value $($_.Value) } # if if ($_.Name -eq 's_name') { Write-Warning -Message "Proccesing: $($_.Name), $($_.Value)" $PSObject | Add-Member -MemberType NoteProperty -Name $($_.Name) -Value $($_.Value) } # if if ($_.Name -eq 's_season_id') { Write-Warning -Message "Proccesing: $($_.Name), $($_.Value)" $PSObject | Add-Member -MemberType NoteProperty -Name $($_.Name) -Value $($_.Value) } # if } # foreach-object $ContinentCompetitions = Select-FootballCompetition -Continent $Continent $Competitions = Get-Competition foreach ($Competition in $ContinentCompetitions) { $CompetitonName = $Competitions[$($Competition.Name)] $Identifier = Get-LeagueIdentifier -Competition $($Competition.Name) if ($($PSObject.s_league_id) -eq $Identifier) { $Date = Get-Date -Format FileDateTimeUniversal $PSObject | Add-Member -MemberType NoteProperty -Name 'competition_name' -Value $CompetitonName $PSObject | Add-Member -MemberType NoteProperty -Name 'date_added' -Value $Date $PSObject | Export-Csv -Path "$ParentPath\$Continent-$Type.csv" -Append -ErrorAction Stop } } # foreach } # foreach } catch { "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # try catch } # process } # function |