summary refs log tree commit diff stats
path: root/tools/nimgrab.nim
blob: 2fa50e89a26868dfbb37ae00bd1bee4253d08637 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os, asyncdispatch, httpclient

proc syncDownload(url, file: string) =
  var client = newHttpClient()
  proc onProgressChanged(total, progress, speed: BiggestInt) =
    echo "Downloading " & url & " " & $(speed div 1000) & "kb/s"
    echo clamp(int(progress*100 div total), 0, 100), "%"

  client.onProgressChanged = onProgressChanged
  client.downloadFile(url, file)
  echo "100%"

if os.paramCount() != 2:
  quit "Usage: nimgrab <url> <file>"
else:
  syncDownload(os.paramStr(1), os.paramStr(2))