File: download.py

package info (click to toggle)
geventhttpclient 2.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ansic: 16,557; python: 3,823; makefile: 24
file content (23 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python

from gevent import monkey

monkey.patch_all()

import tempfile
from pathlib import Path

from geventhttpclient import UserAgent

DL_1MB = "https://proof.ovh.net/files/1Mb.dat"
DL_10MB = "https://proof.ovh.net/files/10Mb.dat"

url = DL_10MB


with tempfile.TemporaryDirectory() as tmp_dir:
    fpath = Path(tmp_dir) / url.rsplit("/", 1)[-1]
    print(f"Writing to {fpath}")
    UserAgent().download(url, fpath)
    print(f"{fpath.stat().st_size} bytes downloaded")
    assert fpath.stat().st_size == int(fpath.name.split("M", 1)[0]) * 2**20  # 10 MB