Lesson one project

I use duckduckgi image search nto serch image but when i want save my images it take so long in other words just it busy my computer and does not work. do you have any idea?

Code for image search is:
urls_sun= DDGS().images(
keywords=‘sun photo’,
region=“wt-wt”,
safesearch=“off”,
size=None,
color=“Monochrome”,
type_image=None,
layout=None,
license_image=None,
max_results=1000,
)

cods for save the images are:

names= ‘sun’, ‘earth’
path= Path(‘forest_or_earth’)
from time import sleep

for o in names:
dest= (path/o)
dest.mkdir(exist_ok=True, parents=True) # we build a folder for forest and a folder for earth
download_images(dest, urls= urls_shade ) # we save pictures in dest directory
#sleep(10)
download_images(dest, urls= urls_sun)
#sleep(10)
resize_images(path/o, max_size=400, dest=path/o)

Hello,

Certainly, let’s analyze the code and explore potential solutions to the slow image saving issue.

Possible Causes:

Large Image Size:

If the max_results is set to a high value (1000 in your case), you’re downloading a significant number of images.
Downloading and potentially resizing large images can consume considerable system resources, leading to slow performance.
Network Speed:

The speed of your internet connection plays a crucial role. Slow download speeds will directly impact the overall time taken to save images.
Disk I/O:

If your hard drive is slow or nearly full, it can significantly slow down the process of saving numerous files.
Image Processing:

The resize_images function might be computationally expensive, especially if you’re dealing with a large number of images.
DuckDuckGo API Limitations:

There might be rate limits or other limitations imposed by the DuckDuckGo API that could slow down the image retrieval process.
Optimization Strategies:

Reduce Image Count:

Lower the max_results parameter in DDGS().images() to a smaller value (e.g., 100 or 200). This will significantly reduce the number of images to download and process.
Download Smaller Images:

Consider using the size parameter in DDGS().images() to specify a smaller image size (e.g., ‘small’, ‘medium’). This will reduce the download time and the processing load.
Optimize Downloading:

Use asynchronous or concurrent downloads to speed up the process. Libraries like asyncio or concurrent.futures can help you download multiple images simultaneously.
Improve Disk I/O:

Ensure you have sufficient free space on your hard drive.
Consider using a faster storage medium (e.g., an SSD) if possible.
Optimize Resizing:

Explore more efficient image resizing libraries (e.g., Pillow with optimized algorithms).
Consider using a lower resolution for resizing.
Handle Errors and Rate Limits:

Implement error handling and retry mechanisms to deal with network issues or API rate limits.
Introduce appropriate delays or backoff strategies to avoid overwhelming the server.

Best Regards
bella964