-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpic_DL.py
More file actions
executable file
·49 lines (41 loc) · 1.38 KB
/
pic_DL.py
File metadata and controls
executable file
·49 lines (41 loc) · 1.38 KB
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
# DO NOT ADD tailing slash for location of files
# The first column of the csv file is the nam eof the file
import sys, os, multiprocessing, csv, urllib.request
from os.path import basename
#Reads the csv for the item number and creates the link supporting the web location
def readgetURLs(filename):
urls = []
with open(filename) as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
prefix = 'xxx'
urls.append(prefix+row[0]+'.jpg')
return urls
#Downloads the image
def download_image(url):
print(location+'/'+basename(url))
try:
urllib.request.urlretrieve(url, location+'/'+basename(url))
except:
pass
# Main function to start everything
def loader():
if len(sys.argv) != 3:
print('Syntax: {} <inv_file.csv> <output_dir/>'.format(sys.argv[0]))
sys.exit(0)
(inv_file, out_dir) = sys.argv[1:]
if not os.path.exists(out_dir):
os.mkdir(out_dir)
global location
location = out_dir
url_list = readgetURLs(inv_file)
pool = multiprocessing.Pool(processes=4) # Num of CPUs
print('Beginning file download...')
pool.map(download_image, url_list)
pool.close()
pool.terminate()
print('Reguested Files Downloaded...')
# arg1 : inv_file.csv
# arg2 : output_dir
if __name__ == '__main__':
loader()