-
Notifications
You must be signed in to change notification settings - Fork 4
/
nsfwDataset.py
38 lines (34 loc) · 1.2 KB
/
nsfwDataset.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import requests
def imageDownload(url, folder):
file_name = url.split("/")[-1]
file_path = folder + "\\" + file_name
if os.path.exists(file_path):
print(file_path, "is exists, skip")
return
print("Downloading %s from %s" % (file_name, url))
try:
download_file = requests.get(url)
status = download_file.status_code
if status == 200:
with open(file_path, 'wb') as outfile:
outfile.write(download_file.content)
else:
print("download fail")
except:
print("download fail")
if __name__ == "__main__":
rootdir = "E:\\nsfw_data_source_urls"
for dirpath, dirnames, filenames in os.walk(rootdir):
if len(filenames) > 0:
for filename in filenames:
suffix = filename.split(".")[-1]
if suffix != "txt":
continue
path = os.path.join(dirpath, filename)
with open(path, 'r') as f:
lines = f.readlines()
for url in lines:
imageDownload(url.strip(), dirpath)