Created
August 23, 2018 09:55
-
-
Save dukn/19a8e693d5443efd40f18a5bdb723b2a to your computer and use it in GitHub Desktop.
download image form link farallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import wget | |
import pandas as pd | |
from multiprocessing import Pool | |
FILE_PATH = sys.argv[1] | |
def get_file_paths(FILE_PATH): | |
df = pd.read_csv(FILE_PATH, header=None) | |
res = df[0].tolist() | |
print (len(res)) | |
return res | |
def downloader(link): | |
try: | |
wget.download(link, 'data/' + link.split('/')[-1]) | |
return 1 | |
except Exception as e: | |
print (e) | |
return 0 | |
def main(): | |
if not os.path.isdir('data'): | |
os.mkdir('data') | |
list_file = list(get_file_paths(FILE_PATH)) | |
p = Pool(8) | |
data = p.map(downloader, list_file) | |
print (sum(data)/float(len(data))) | |
if __name__ == '__main__': | |
#get_file_paths(FILE_PATH) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment