forked from andrewjong/ShineOn-Virtual-Tryon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_download.py
54 lines (44 loc) · 1.58 KB
/
data_download.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import re
import shutil
import sys
import tarfile
import requests
def download(url, filename, cookies=None):
with open(filename, "wb") as f:
response = requests.get(url, stream=True, cookies=cookies)
total = response.headers.get("content-length")
if total is None:
f.write(response.content)
else:
downloaded = 0
total = int(total)
for data in response.iter_content(
chunk_size=max(int(total / 1000), 1024 * 1024)
):
downloaded += len(data)
f.write(data)
completed = int(50 * downloaded / total)
sys.stdout.write(
"\r[{}{}]".format("█" * completed, "." * (50 - completed))
)
sys.stdout.flush()
sys.stdout.write("\n")
drive_request = requests.get(
"https://drive.google.com/uc?export=download&confirm=CONFIRM&id=1MxCUvKxejnwWnoZ-KoCyMCXo3TLhRuTo"
)
confirm_page = drive_request.text
confirmation_code = re.findall("confirm=(.{4})", confirm_page)[0]
print("[*] Downloading data...")
download(
"https://drive.google.com/uc?export=download&confirm=CONFIRM&id=1MxCUvKxejnwWnoZ-KoCyMCXo3TLhRuTo".replace(
"CONFIRM", confirmation_code
),
"data/viton_resize.tar.gz",
cookies=drive_request.cookies,
)
tarfile.open("data/viton_resize.tar.gz").extractall(path="data/")
shutil.move("data/viton_resize/test/", "data/test/")
shutil.move("data/viton_resize/train/", "data/train/")
os.rmdir("data/viton_resize/")
os.remove("data/viton_resize.tar.gz")