pexels (849B)
1 #!/bin/bash 2 3 # wp -- a wallpaper switcher 4 # Copyright 2022 Matthias Balk 5 6 # requires `bash` (for $RANDOM), `bc`, `curl` and `jq` 7 8 # configuration 9 SEARCH_TERM='Norwegen' 10 LOCALE='de-DE' 11 API_SECRET='YOUR PEXELS.COM API SECRET GOES HERE!' 12 PICS_COUNT=80 # number of pics to choose from; max 80, default 15 13 # end configuration 14 15 data="`mktemp`" 16 curl -s -H "Authorization: $API_SECRET" \ 17 "https://api.pexels.com/v1/search?query=$SEARCH_TERM&locale=$LOCALE&per_page=$PICS_COUNT&page=1" \ 18 > $data 19 20 results=`jq -r ".total_results" $data` 21 if [ "$results" = "0" -o "$results" = "null" -o "$results" = "" ]; then 22 exit 1 23 fi 24 25 if [ $results -lt $PICS_COUNT ]; then 26 mod=$results 27 else 28 mod=$PICS_COUNT 29 fi 30 RANDOM=$$ 31 pic=`echo "$RANDOM % $mod" | bc` 32 url=`jq -r ".photos[$pic].src.original" $data` 33 34 target="`mktemp`" 35 curl -s "$url" > "$target" 36 echo $target