mathiaszinnen commited on
Commit
9507809
·
1 Parent(s): 03e0a5c

remove unused download_utils.py file

Browse files
Files changed (1) hide show
  1. download_utils.py +0 -45
download_utils.py DELETED
@@ -1,45 +0,0 @@
1
- import os
2
- import time
3
-
4
- import requests
5
- import pandas as pd
6
- from tqdm import tqdm
7
- from multiprocessing.pool import ThreadPool
8
- from multiprocessing import cpu_count
9
- from pathlib import Path
10
- from requests.exceptions import MissingSchema, Timeout, ConnectionError, InvalidSchema
11
-
12
-
13
- def download_one(entry, overwrite=False):
14
- fn, uri, target_pth, retries = entry
15
- fn = fn.replace("/", "_")
16
- path = f'{target_pth}/{fn}'
17
- if os.path.exists(path) and not overwrite:
18
- return fn
19
-
20
- for i in range(retries):
21
- try:
22
- r = requests.get(uri, stream=True, timeout=50)
23
- except (MissingSchema, Timeout, ConnectionError, InvalidSchema):
24
- time.sleep(i)
25
- continue
26
-
27
- if r.status_code == 200:
28
- with open(path, 'wb') as f:
29
- for chunk in r:
30
- f.write(chunk)
31
- return fn
32
- else:
33
- time.sleep(i)
34
- continue
35
-
36
- return fn
37
-
38
-
39
- def download_all(metadata_pth, target_pth, retries=3):
40
- df = pd.read_csv(metadata_pth)
41
- entries = [[*x, target_pth, retries] for x in df[['File Name', 'Image Credits']].values]
42
- n_processes = max(1, cpu_count() - 1)
43
- with ThreadPool(n_processes) as p:
44
- results = list(tqdm(p.imap(download_one, entries), total=len(entries)))
45
- return results