Advertisement
shared_prophet

random wallpaper collection

Jul 13th, 2019 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. folder=$1
  3. res=$2
  4. list=$folder/list.txt
  5. touch "$list"
  6. for i in $(seq -f "%03g" 0 599); do
  7.   while [ ! -f "$folder/$i.jpg" ]; do
  8.     current=$(curl -si https://source.unsplash.com/random/$res | grep 'Location: ' | cut -d ' ' -f 2 | tr -d '[:space:]')
  9.     found=false
  10.    
  11.     echo checking list for $current...
  12.    
  13.     while IFS= read -r line; do
  14.       if [ "$line" == "$current" ]; then
  15.         found=true
  16.         break
  17.       fi
  18.     done < "$list"
  19.    
  20.     if [ "$found" == "false" ]; then
  21.       echo file not found, downloading...
  22.       curl -Lf -o "$folder/$i.jpg" $current && echo $current >> $list
  23.     else
  24.       echo file found, skipping...
  25.     fi
  26.    
  27.     sleep 4
  28.   done
  29. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement