Skip to content

Instantly share code, notes, and snippets.

@amis92
Last active November 3, 2020 11:51
Show Gist options
  • Save amis92/ffa4500d12aa712c0524cc748cf09c91 to your computer and use it in GitHub Desktop.
Save amis92/ffa4500d12aa712c0524cc748cf09c91 to your computer and use it in GitHub Desktop.
unifying publications in wh40k
# in repo directory
$files = dir * -Include *.cat,*.gst
$datas = $files | % { [xml] (cat $_) }
$roots = @($datas.catalogue, $datas.gameSystem) | % { $_ } | ? {$_}

# show all unique pub names
$roots.publications.publication.name | % { $_ } | select -Unique | sort

# find all publications (by name) that appear in more than one file
$grp = $roots.publications.publication | Group-Object -Property name
$grp | ? Count -gt 1 | select Name,@{l='catalogues';e={$_.Group.ParentNode.ParentNode.name -join ', '}}
# or
# $files|%{[xml](cat $_)}|%{$_.catalogue;$_.gameSystem}|%{$_}|?{$_}| % { "--- " +$_.name; $_.publications.publication.name | % { $_ } | sort }

# find unreferenced publications
$pubs = $roots.publications.publication
for ($i = 0; $i -lt $pubs.Count; $i++) {
    $pub = $pubs[$i]
    $id = $pub.id
    $name = $pub.name
    $catName = $pub.ParentNode.ParentNode.name
    Write-Progress "Searching for unreferenced publications..." -Status "Checking publications in $catName" -CurrentOperation "$name ($id)" -PercentComplete (100 * $i / $pubs.Count)
    $hits = $files | Select-String $id -SimpleMatch -CaseSensitive | Measure-Object
    if ($hits.Count -eq 1) {
        Write-Output "pubId $id has only single match"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment