self.lock.release()

    def start_downloader(self):
        start_time = datetime.now()
        self.build_image_folder()
        urls = self.build_query_url()
        self.pool.map(self.revolveImageURL,urls)
        resolve_time = datetime.now()
        print('解析網址共花',resolve_time-start_time)
        while self.imageURL.qsize():
            url = self.imageURL.get()
            self.pool.map(self.saveImage,url)
        self.pool.close()
        self.pool.join()
        endtime = datetime.now()
        print('下載結束,共花了',endtime-resolve_time)
        print('共下載',self.index-self.start_index,'張圖片')
        print('共',self.error,'個圖片網址無法獲取')
        return self.index-1

if __name__ == '__main__':
    if downloader_setting.is_python3():
        search = input('關鍵字:')
    else:
        search = raw_input('關鍵字:')

    mydownloader = downloader(search)
    mydownloader.start_downloader()


示例#2
0
            not_image.append(filename)
    for filename in not_image:
        filenames.remove(filename)
    return filenames


def build_subfolder(folder_dir):
    name_list = ['train', 'validation']
    for name in name_list:
        subfolder_dir = os.path.join(folder_dir, name)
        if not os.path.exists(subfolder_dir):
            os.makedirs(subfolder_dir)


if __name__ == '__main__':
    if is_python3():
        DIR = input('input folder directory:')
    else:
        DIR = raw_input('input folder directory:')
    build_subfolder(DIR)
    filenames = get_filenames(DIR)
    print(filenames)

    num = len(filenames)
    train_num = num * 4 // 5
    val_num = num // 5
    random.shuffle(filenames)
    train = filenames[:train_num]
    validation = filenames[train_num:]

    folder_list = [train, validation]