-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
28 lines (25 loc) · 774 Bytes
/
util.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
25
26
27
28
import requests
from tqdm import tqdm
import os
def download(url: str, fname: str, chunk_size=1024): #1024 for 1kB
resp = requests.get(url, stream=True)
total = int(resp.headers.get('content-length', 0))
# tmp_file='tmp.pdf'
tmp_file='cache/'+fname
with open(tmp_file, 'wb') as file, tqdm(
desc=fname,
total=total,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for data in resp.iter_content(chunk_size=chunk_size):
size = file.write(data)
bar.update(size)
os.system(f'mv {tmp_file} {fname}')
def test():
url = 'http://arxiv.org/pdf/q-alg/9508008v1'
fname='q-alg.9508008v1.pdf'
download(url,fname)
if __name__=="__main__":
test()