massinspiro/massinspiro.zsh

41 lines
1 KiB
Bash
Raw Normal View History

2025-01-01 04:13:47 +00:00
#!/bin/zsh
if [[ -z "$1" ]]; then
echo "Please define how many images you wish to download"
exit 1
fi
# Define the output directory for the images
output_dir="./massinspiro_id_$RANDOM$RANDOM$RANDOM"
# Create the directory if it doesn't exist
mkdir -p "$output_dir"
# Loop to get and download the image 4 times
for i in {1..$1}; do
# Get the URL from the API
image_url=$(curl -s "https://inspirobot.me/api?generate=true")
# Check if the URL was retrieved
if [[ -z "$image_url" ]]; then
echo "Failed to get image URL for iteration $i"
continue
fi
# Define the image filename
image_filename="image_$i.jpg"
# Download the image to the specified output directory
echo "Downloading image $i from $image_url"
curl -s -o "$output_dir/$(basename $image_url)" "$image_url"
# Check if the download was successful
if [[ $? -eq 0 ]]; then
echo "Image $i downloaded successfully."
else
echo "Failed to download image $i."
fi
done