Skip to content

Instantly share code, notes, and snippets.

@sayedihashimi
Created September 18, 2016 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayedihashimi/2b8f352d35f2627ac78569325a7789f6 to your computer and use it in GitHub Desktop.
Save sayedihashimi/2b8f352d35f2627ac78569325a7789f6 to your computer and use it in GitHub Desktop.
Download Nalimov table bases (3/4/5)
[cmdletbinding()]
param()
function DownloadTablebases{
[cmdletbinding()]
param(
$baseUrl = 'http://www.chesskit.com/download/nalimov',
$allFilename = 'all.txt',
$downloadRoot = ($pwd)
)
process{
try{
Push-Location
Set-Location $downloadRoot
# check for the all.txt, if it's not there then download it
$allTxtPath = (Join-Path $downloadRoot $allFilename)
if(-not (Test-Path $allTxtPath)){
$allUrl = "$baseUrl/$allFilename"
'Downloading all file from [{0}] to [{1}]' -f $allUrl, $allTxtPath | Write-Verbose
Invoke-WebRequest -Uri $allUrl -OutFile $allTxtPath
}
Get-Content $allTxtPath | % {
$currentline = $_
if(-not [string]::IsNullOrWhiteSpace($currentline)){
$currentline = $currentline.trim()
}
if([string]::Compare($allFilename,$currentline,[System.StringComparison]::OrdinalIgnoreCase) -ne 0){
# see if the file exists locally and if not then redownload it
$currentfile = (Join-Path $downloadRoot $currentline)
if(-not(Test-Path $currentfile)){
$dlurl = "$baseUrl/$currentline"
'Downloading file from [{0}] to [{1}]' -f $baseUrl, $currentfile | Write-Verbose
Invoke-WebRequest -Uri $dlurl -OutFile $currentfile
}
}
}
}
finally{
Pop-Location
}
}
}
DownloadTablebases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment