Created
June 27, 2019 12:45
-
-
Save cpebble/c0b0aef7bc557aeb80b6f7bf695c8959 to your computer and use it in GitHub Desktop.
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 | |
echo Fetching reddit links | |
postJSON=$(curl -s 'https://www.reddit.com/r/wallpapers.json?limit=100' -A "Wallpaper fetcher by /u/cpcp800") | |
# OMG fucking sed horrorbeast no judging | |
resolutions=$(resolutions | sed 's/.*\([0-9][0-9][0-9][0-9]x[0-9][0-9][0-9][0-9]\+\).*/\1/') | |
echo JSON Fetched | |
parseJSON () { | |
echo $postJSON | jq --arg HEIGHT "$1" --arg WIDTH "$2" '.data.children[] | |
| select( | |
.data.title | |
| . and contains($HEIGHT) and contains($WIDTH) | |
) | |
| .data.url' | |
} | |
getRandomInList () { | |
echo "$@" | tr " " "\n" | shuf -n 1 | |
} | |
urls='' | |
for res in $resolutions; do | |
h=$(cut -d x -f 2 <<< $res ) | |
w=$(cut -d x -f 1 <<< $res ) | |
imgs=$(parseJSON $h $w) | |
echo "found images($h x $w ):$(wc -l <<<$imgs)" | |
urls="$urls $(getRandomInList $imgs)" | |
done | |
echo $urls | |
/bin/sh -c "feh --bg-center $urls" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment