-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl.py
24 lines (20 loc) · 892 Bytes
/
dl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests
def download_file(url, dest_local_file, log_prefix="") -> bool:
log_prefix_local = log_prefix + "download_file: "
try:
with requests.get(url, stream=True) as response:
if response and response.status_code == 200:
with open(dest_local_file, "wb") as fout:
for chunk in response.iter_content(chunk_size=8192):
fout.write(chunk)
return True
else:
print(
f"{log_prefix_local}Error: Server responded with status code {response=}"
)
return False
except Exception as exc:
print(f"{log_prefix_local}Exception occurred: {exc}")
return False
download_file("https://www.timstewart.io/lipsum.html", "lipsum.html")
download_file("https://www.hayfevr.ly/images/hf.webp", "hf.webp")