Skip to content

Instantly share code, notes, and snippets.

@loadenmb
Created October 10, 2019 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save loadenmb/08203f3467965776caea6b44d6f88fe3 to your computer and use it in GitHub Desktop.
Save loadenmb/08203f3467965776caea6b44d6f88fe3 to your computer and use it in GitHub Desktop.
Bulk download random images with predefined keywords and size from loremflickr.com to current directory
#!/bin/bash
# bulk download random images with predefined keywords and size from loremflickr.com to current directory
# config
KEYWORDS="beach,girl" # search keywords comma separated
WIDTH=800 # image width
HEIGHT=600 # image high
COUNT=2 # image count
MAXTRIALS=3 # max errors until stop
i=0
k=0
while [ $i -lt $COUNT ]
do
wget "https://loremflickr.com/g/${WIDTH}/${HEIGHT}/${KEYWORDS}/all" -O "${i}.jpg" # loremflickr.com returns random image
if [ "$?" -ne 0 ]; then
k=$[$k+1]
if [ "$k" == "$MAXTRIALS" ]; then
echo "too many errors. abort..."
exit 1
fi
continue;
fi
k=0
i=$[$i+1]
sleep 0.5 # wait after each request, do not send too many in short time
done
@adriantabirta
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment