You are on page 1of 1

import requests

from joblib import Parallel, delayed


import textile

def download_image(url, output_path):


try:
response = requests.get(url)
if response.status_code == 200:
with open(output_path, 'wb') as f:
f.write(response.content)
print(f"Downloaded: {url}")
else:
print(f"Failed to download: {url}")
except Exception as e:
print(f"Error while downloading {url}: {str(e)}")

def download_images_from_textile(textile_key, output_dir):


textile_client = textile.Textile()
textile_data = textile_client.get(textile_key)
urls = textile_data.split('\n')

# Create the output directory if it doesn't exist


import os
os.makedirs(output_dir, exist_ok=True)

# Use joblib to parallelize the image downloads


Parallel(n_jobs=-1)(delayed(download_image)(url, f"{output_dir}/{i}.jpg") for
i, url in enumerate(urls))

if __name__ == "__main__":
textile_key = "your_textile_key_here" # Replace with your Textile key
output_directory = "downloaded_images" # Change to your desired output
directory

download_images_from_textile(textile_key, output_directory)

You might also like