File: nimgrab.nim

package info (click to toggle)
nim 1.6.14-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,181,140 kB
  • sloc: sh: 20,999; ansic: 1,722; makefile: 958; python: 461; sql: 298; asm: 141; xml: 13
file content (16 lines) | stat: -rw-r--r-- 495 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import std/[os, 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))