Created
October 10, 2019 08:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx